Added theme support vars for grid settings
- product_grid - min_rows - max_rows - min_columns - max_columns If settings violate these, they will be updated. If loop_shop_columns is defined, settings are hidden with a notice.
This commit is contained in:
parent
2a3ace9853
commit
d765e2319c
|
@ -76,7 +76,9 @@ class WC_Settings_Products extends WC_Settings_Page {
|
|||
*/
|
||||
public function get_settings( $current_section = '' ) {
|
||||
if ( 'display' === $current_section ) {
|
||||
$settings = array(
|
||||
$theme_support = get_theme_support( 'woocommerce' );
|
||||
$theme_support = is_array( $theme_support ) ? $theme_support[0]: false;
|
||||
$settings = array(
|
||||
array(
|
||||
'title' => __( 'Shop & product pages', 'woocommerce' ),
|
||||
'type' => 'title',
|
||||
|
@ -141,7 +143,7 @@ class WC_Settings_Products extends WC_Settings_Page {
|
|||
) ),
|
||||
'desc_tip' => true,
|
||||
),
|
||||
array(
|
||||
'columns' => array(
|
||||
'title' => __( 'Products per row', 'woocommerce' ),
|
||||
'desc' => __( 'How many products should be shown per row?', 'woocommerce' ),
|
||||
'id' => 'woocommerce_catalog_columns',
|
||||
|
@ -149,13 +151,13 @@ class WC_Settings_Products extends WC_Settings_Page {
|
|||
'type' => 'number',
|
||||
'css' => 'width: 50px;',
|
||||
'custom_attributes' => array(
|
||||
'min' => 0,
|
||||
'step' => 1,
|
||||
'min' => isset( $theme_support['product_grid']['min_columns'] ) ? absint( $theme_support['product_grid']['min_columns'] ) : 1,
|
||||
'max' => isset( $theme_support['product_grid']['max_columns'] ) ? absint( $theme_support['product_grid']['max_columns'] ) : '',
|
||||
'step' => 1,
|
||||
),
|
||||
'desc_tip' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'rows' => array(
|
||||
'title' => __( 'Rows per page', 'woocommerce' ),
|
||||
'desc' => __( 'How many rows of products should be shown per page?', 'woocommerce' ),
|
||||
'id' => 'woocommerce_catalog_rows',
|
||||
|
@ -163,12 +165,12 @@ class WC_Settings_Products extends WC_Settings_Page {
|
|||
'type' => 'number',
|
||||
'css' => 'width: 50px;',
|
||||
'custom_attributes' => array(
|
||||
'min' => 0,
|
||||
'step' => 1,
|
||||
'min' => isset( $theme_support['product_grid']['min_rows'] ) ? absint( $theme_support['product_grid']['min_rows'] ): 1,
|
||||
'max' => isset( $theme_support['product_grid']['max_rows'] ) ? absint( $theme_support['product_grid']['max_rows'] ): '',
|
||||
'step' => 1,
|
||||
),
|
||||
'desc_tip' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Add to cart behaviour', 'woocommerce' ),
|
||||
'desc' => __( 'Redirect to the cart page after successful addition', 'woocommerce' ),
|
||||
|
@ -190,8 +192,11 @@ class WC_Settings_Products extends WC_Settings_Page {
|
|||
),
|
||||
);
|
||||
|
||||
$theme_support = get_theme_support( 'woocommerce' );
|
||||
$theme_support = is_array( $theme_support ) ? $theme_support[0]: false;
|
||||
if ( has_filter( 'loop_shop_columns' ) ) {
|
||||
wc_deprecated_function( 'The loop_shop_columns filter', '3.3', 'the woocomerce add_theme_support declaration, or remove the filter and set in product settings' );
|
||||
unset( $settings['columns'], $settings['rows'] );
|
||||
}
|
||||
|
||||
$image_settings = array(
|
||||
array(
|
||||
'title' => __( 'Product images', 'woocommerce' ),
|
||||
|
|
|
@ -688,8 +688,8 @@ function wc_get_image_size( $image_size ) {
|
|||
$image_size = $size['width'] . '_' . $size['height'];
|
||||
} elseif ( in_array( $image_size, array( 'single', 'shop_single' ), true ) ) {
|
||||
// If the theme supports woocommerce, take image sizes from that definition.
|
||||
if ( isset( $theme_support[ 'single_image_width' ] ) ) {
|
||||
$size['width'] = $theme_support[ 'single_image_width' ];
|
||||
if ( isset( $theme_support['single_image_width'] ) ) {
|
||||
$size['width'] = $theme_support['single_image_width'];
|
||||
} else {
|
||||
$size['width'] = get_option( 'woocommerce_single_image_width', 600 );
|
||||
}
|
||||
|
@ -698,8 +698,8 @@ function wc_get_image_size( $image_size ) {
|
|||
$image_size = 'single';
|
||||
} elseif ( in_array( $image_size, array( 'thumbnail', 'shop_thumbnail', 'shop_catalog' ), true ) ) {
|
||||
// If the theme supports woocommerce, take image sizes from that definition.
|
||||
if ( isset( $theme_support[ 'thumbnail_image_width' ] ) ) {
|
||||
$size['width'] = $theme_support[ 'thumbnail_image_width' ];
|
||||
if ( isset( $theme_support['thumbnail_image_width'] ) ) {
|
||||
$size['width'] = $theme_support['thumbnail_image_width'];
|
||||
} else {
|
||||
$size['width'] = get_option( 'woocommerce_thumbnail_image_width', 300 );
|
||||
}
|
||||
|
|
|
@ -289,6 +289,18 @@ function wc_product_cat_class( $class = '', $category = null ) {
|
|||
function wc_get_default_products_per_row() {
|
||||
$columns = get_option( 'woocommerce_catalog_columns', 3 );
|
||||
|
||||
// Theme support.
|
||||
$theme_support = get_theme_support( 'woocommerce' );
|
||||
$theme_support = is_array( $theme_support ) ? $theme_support[0]: false;
|
||||
|
||||
if ( isset( $theme_support['product_grid']['min_columns'] ) && $columns < $theme_support['product_grid']['min_columns'] ) {
|
||||
$columns = $theme_support['product_grid']['min_columns'];
|
||||
update_option( 'woocommerce_catalog_columns', $columns );
|
||||
} elseif ( ! empty( $theme_support['product_grid']['max_columns'] ) && $columns > $theme_support['product_grid']['max_columns'] ) {
|
||||
$columns = $theme_support['product_grid']['max_columns'];
|
||||
update_option( 'woocommerce_catalog_columns', $columns );
|
||||
}
|
||||
|
||||
// Legacy filter.
|
||||
if ( has_filter( 'loop_shop_columns' ) ) {
|
||||
$columns = apply_filters( 'loop_shop_columns', $columns );
|
||||
|
@ -305,7 +317,21 @@ function wc_get_default_products_per_row() {
|
|||
* @return int
|
||||
*/
|
||||
function wc_get_default_product_rows_per_page() {
|
||||
return absint( get_option( 'woocommerce_catalog_rows', 4 ) );
|
||||
$rows = absint( get_option( 'woocommerce_catalog_rows', 4 ) );
|
||||
|
||||
// Theme support.
|
||||
$theme_support = get_theme_support( 'woocommerce' );
|
||||
$theme_support = is_array( $theme_support ) ? $theme_support[0]: false;
|
||||
|
||||
if ( isset( $theme_support['product_grid']['min_rows'] ) && $rows < $theme_support['product_grid']['min_rows'] ) {
|
||||
$rows = $theme_support['product_grid']['min_rows'];
|
||||
update_option( 'woocommerce_catalog_rows', $rows );
|
||||
} elseif ( ! empty( $theme_support['product_grid']['max_rows'] ) && $rows > $theme_support['product_grid']['max_rows'] ) {
|
||||
$rows = $theme_support['product_grid']['max_rows'];
|
||||
update_option( 'woocommerce_catalog_rows', $rows );
|
||||
}
|
||||
|
||||
return $rows;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue