Conditional settings

This commit is contained in:
Mike Jolley 2017-11-14 16:38:39 +00:00
parent 992d6e3aed
commit e222cfc9fa
1 changed files with 101 additions and 95 deletions

View File

@ -101,111 +101,117 @@ class WC_Customizer {
/** /**
* Grid settings. * Grid settings.
*/ */
$wp_customize->add_setting( if ( ! has_filter( 'loop_shop_columns' ) ) {
'woocommerce_catalog_columns', $wp_customize->add_setting(
array( 'woocommerce_catalog_columns',
'default' => 3, array(
'type' => 'option', 'default' => 3,
'capability' => 'manage_woocommerce', 'type' => 'option',
'sanitize_callback' => 'absint', 'capability' => 'manage_woocommerce',
'sanitize_js_callback' => 'absint', 'sanitize_callback' => 'absint',
) 'sanitize_js_callback' => 'absint',
); )
);
$wp_customize->add_control( $wp_customize->add_control(
'woocommerce_catalog_columns', 'woocommerce_catalog_columns',
array( array(
'label' => __( 'Products per row', 'woocommerce' ), 'label' => __( 'Products per row', 'woocommerce' ),
'description' => __( 'How many products should be shown per row?', 'woocommerce' ), 'description' => __( 'How many products should be shown per row?', 'woocommerce' ),
'section' => 'woocommerce_product_display_settings', 'section' => 'woocommerce_product_display_settings',
'settings' => 'woocommerce_catalog_columns', 'settings' => 'woocommerce_catalog_columns',
'type' => 'number', 'type' => 'number',
'input_attrs' => array( 'input_attrs' => array(
'min' => isset( $theme_support['product_grid']['min_columns'] ) ? absint( $theme_support['product_grid']['min_columns'] ) : 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'] ) : '', 'max' => isset( $theme_support['product_grid']['max_columns'] ) ? absint( $theme_support['product_grid']['max_columns'] ) : '',
'step' => 1, 'step' => 1,
), ),
) )
); );
$wp_customize->add_setting( $wp_customize->add_setting(
'woocommerce_catalog_rows', 'woocommerce_catalog_rows',
array( array(
'default' => 4, 'default' => 4,
'type' => 'option', 'type' => 'option',
'capability' => 'manage_woocommerce', 'capability' => 'manage_woocommerce',
'sanitize_callback' => 'absint', 'sanitize_callback' => 'absint',
'sanitize_js_callback' => 'absint', 'sanitize_js_callback' => 'absint',
) )
); );
$wp_customize->add_control( $wp_customize->add_control(
'woocommerce_catalog_rows', 'woocommerce_catalog_rows',
array( array(
'label' => __( 'Rows per page', 'woocommerce' ), 'label' => __( 'Rows per page', 'woocommerce' ),
'description' => __( 'How many rows of products should be shown per page?', 'woocommerce' ), 'description' => __( 'How many rows of products should be shown per page?', 'woocommerce' ),
'section' => 'woocommerce_product_display_settings', 'section' => 'woocommerce_product_display_settings',
'settings' => 'woocommerce_catalog_rows', 'settings' => 'woocommerce_catalog_rows',
'type' => 'number', 'type' => 'number',
'input_attrs' => array( 'input_attrs' => array(
'min' => isset( $theme_support['product_grid']['min_rows'] ) ? absint( $theme_support['product_grid']['min_rows'] ): 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'] ): '', 'max' => isset( $theme_support['product_grid']['max_rows'] ) ? absint( $theme_support['product_grid']['max_rows'] ): '',
'step' => 1, 'step' => 1,
), ),
) )
); );
}
/** /**
* Image settings. * Image settings.
*/ */
$wp_customize->add_setting( if ( ! isset( $theme_support['single_image_width'] ) ) {
'single_image_width', $wp_customize->add_setting(
array( 'single_image_width',
'default' => 600, array(
'type' => 'option', 'default' => 600,
'capability' => 'manage_woocommerce', 'type' => 'option',
'sanitize_callback' => 'absint', 'capability' => 'manage_woocommerce',
'sanitize_js_callback' => 'absint', 'sanitize_callback' => 'absint',
) 'sanitize_js_callback' => 'absint',
); )
);
$wp_customize->add_control( $wp_customize->add_control(
'single_image_width', 'single_image_width',
array( array(
'label' => __( 'Main image width', 'woocommerce' ), 'label' => __( 'Main image width', 'woocommerce' ),
'description' => __( 'This is the width used by the main image on single product pages. These images will remain uncropped.', 'woocommerce' ), 'description' => __( 'This is the width used by the main image on single product pages. These images will remain uncropped.', 'woocommerce' ),
'section' => 'woocommerce_product_display_settings', 'section' => 'woocommerce_product_display_settings',
'settings' => 'single_image_width', 'settings' => 'single_image_width',
'type' => 'number', 'type' => 'number',
'input_attrs' => array( 'input_attrs' => array(
'min' => 0, 'min' => 0,
'step' => 1, 'step' => 1,
), ),
) )
); );
}
$wp_customize->add_setting( if ( ! isset( $theme_support['thumbnail_image_width'] ) ) {
'thumbnail_image_width', $wp_customize->add_setting(
array( 'thumbnail_image_width',
'default' => 300, array(
'type' => 'option', 'default' => 300,
'capability' => 'manage_woocommerce', 'type' => 'option',
'sanitize_callback' => 'absint', 'capability' => 'manage_woocommerce',
'sanitize_js_callback' => 'absint', 'sanitize_callback' => 'absint',
) 'sanitize_js_callback' => 'absint',
); )
);
$wp_customize->add_control( $wp_customize->add_control(
'thumbnail_image_width', 'thumbnail_image_width',
array( array(
'label' => __( 'Thumbnail width', 'woocommerce' ), 'label' => __( 'Thumbnail width', 'woocommerce' ),
'description' => __( 'This size is used for product archives and product listings.', 'woocommerce' ), 'description' => __( 'This size is used for product archives and product listings.', 'woocommerce' ),
'section' => 'woocommerce_product_display_settings', 'section' => 'woocommerce_product_display_settings',
'settings' => 'thumbnail_image_width', 'settings' => 'thumbnail_image_width',
'type' => 'number', 'type' => 'number',
'input_attrs' => array( 'min' => 0, 'step' => 1 ), 'input_attrs' => array( 'min' => 0, 'step' => 1 ),
) )
); );
}
include_once( WC_ABSPATH . 'includes/customizer/class-wc-customizer-control-cropping.php' ); include_once( WC_ABSPATH . 'includes/customizer/class-wc-customizer-control-cropping.php' );