From a767f11473a28069f7c0c299e3abf03878634d4a Mon Sep 17 00:00:00 2001 From: Caleb Burks <19caleb95@gmail.com> Date: Mon, 11 Dec 2017 19:56:01 -0600 Subject: [PATCH 1/4] Product Grid settings should only show someimtes --- includes/customizer/class-wc-customizer.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/includes/customizer/class-wc-customizer.php b/includes/customizer/class-wc-customizer.php index 27b6e9e04cb..b8fac340f75 100644 --- a/includes/customizer/class-wc-customizer.php +++ b/includes/customizer/class-wc-customizer.php @@ -110,6 +110,15 @@ class WC_Customizer { return is_woocommerce() || wc_post_content_has_shortcode( 'products' ) || ! current_theme_supports( 'woocommerce' ); } + /** + * Should our settings show on product archives? + * + * @return boolean + */ + public function is_products_archive() { + return is_shop() || is_product_taxonomy() || is_product_category() || ! current_theme_supports( 'woocommerce' ); + } + /** * Store notice section. * @@ -185,7 +194,7 @@ class WC_Customizer { array( 'title' => __( 'Product Grid', 'woocommerce' ), 'priority' => 10, - 'active_callback' => array( $this, 'is_active' ), + 'active_callback' => array( $this, 'is_products_archive' ), 'panel' => 'woocommerce', ) ); From 53873857ef8166e8f3e0c015e2848bf5b0ad92d0 Mon Sep 17 00:00:00 2001 From: Caleb Burks <19caleb95@gmail.com> Date: Mon, 11 Dec 2017 22:30:14 -0600 Subject: [PATCH 2/4] Move three display settings to customizer --- .../settings/class-wc-settings-products.php | 48 -------- includes/customizer/class-wc-customizer.php | 110 ++++++++++++++++++ 2 files changed, 110 insertions(+), 48 deletions(-) diff --git a/includes/admin/settings/class-wc-settings-products.php b/includes/admin/settings/class-wc-settings-products.php index 9c770f2c13c..282517d07d4 100644 --- a/includes/admin/settings/class-wc-settings-products.php +++ b/includes/admin/settings/class-wc-settings-products.php @@ -279,54 +279,6 @@ class WC_Settings_Products extends WC_Settings_Page { 'css' => 'min-width:300px;', 'desc_tip' => __( 'This sets the base page of your shop - this is where your product archive will be.', 'woocommerce' ), ), - array( - 'title' => __( 'Shop page display', 'woocommerce' ), - 'desc' => __( 'This controls what is shown on the product archive.', 'woocommerce' ), - 'id' => 'woocommerce_shop_page_display', - 'class' => 'wc-enhanced-select', - 'css' => 'min-width:300px;', - 'default' => '', - 'type' => 'select', - 'options' => array( - '' => __( 'Show products', 'woocommerce' ), - 'subcategories' => __( 'Show categories', 'woocommerce' ), - 'both' => __( 'Show categories & products', 'woocommerce' ), - ), - 'desc_tip' => true, - ), - array( - 'title' => __( 'Default category display', 'woocommerce' ), - 'desc' => __( 'This controls what is shown on category archives.', 'woocommerce' ), - 'id' => 'woocommerce_category_archive_display', - 'class' => 'wc-enhanced-select', - 'css' => 'min-width:300px;', - 'default' => '', - 'type' => 'select', - 'options' => array( - '' => __( 'Show products', 'woocommerce' ), - 'subcategories' => __( 'Show subcategories', 'woocommerce' ), - 'both' => __( 'Show subcategories & products', 'woocommerce' ), - ), - 'desc_tip' => true, - ), - array( - 'title' => __( 'Default product sorting', 'woocommerce' ), - 'desc' => __( 'This controls the default sort order of the catalog.', 'woocommerce' ), - 'id' => 'woocommerce_default_catalog_orderby', - 'class' => 'wc-enhanced-select', - 'css' => 'min-width:300px;', - 'default' => 'menu_order', - 'type' => 'select', - 'options' => apply_filters( 'woocommerce_default_catalog_orderby_options', array( - 'menu_order' => __( 'Default sorting (custom ordering + name)', 'woocommerce' ), - 'popularity' => __( 'Popularity (sales)', 'woocommerce' ), - 'rating' => __( 'Average rating', 'woocommerce' ), - 'date' => __( 'Sort by most recent', 'woocommerce' ), - 'price' => __( 'Sort by price (asc)', 'woocommerce' ), - 'price-desc' => __( 'Sort by price (desc)', 'woocommerce' ), - ) ), - 'desc_tip' => true, - ), array( 'title' => __( 'Add to cart behaviour', 'woocommerce' ), 'desc' => __( 'Redirect to the cart page after successful addition', 'woocommerce' ), diff --git a/includes/customizer/class-wc-customizer.php b/includes/customizer/class-wc-customizer.php index b8fac340f75..1b4de2db21b 100644 --- a/includes/customizer/class-wc-customizer.php +++ b/includes/customizer/class-wc-customizer.php @@ -119,6 +119,35 @@ class WC_Customizer { return is_shop() || is_product_taxonomy() || is_product_category() || ! current_theme_supports( 'woocommerce' ); } + /** + * Sanitize the shop page & category display setting. + * + * @return array + */ + public function sanitize_archive_display( $value ) { + $options = array( '', 'subcategories', 'both' ); + + return in_array( $value, $options ) ? $value : ''; + } + + /** + * Sanitize the catalog orderby setting. + * + * @return array + */ + public function sanitize_default_catalog_orderby( $value ) { + $options = apply_filters( 'woocommerce_default_catalog_orderby_options', array( + 'menu_order' => __( 'Default sorting (custom ordering + name)', 'woocommerce' ), + 'popularity' => __( 'Popularity (sales)', 'woocommerce' ), + 'rating' => __( 'Average rating', 'woocommerce' ), + 'date' => __( 'Sort by most recent', 'woocommerce' ), + 'price' => __( 'Sort by price (asc)', 'woocommerce' ), + 'price-desc' => __( 'Sort by price (desc)', 'woocommerce' ), + ) ); + + return array_key_exists( $value, $options ) ? $value : 'menu_order'; + } + /** * Store notice section. * @@ -199,6 +228,87 @@ class WC_Customizer { ) ); + $wp_customize->add_setting( + 'woocommerce_shop_page_display', + array( + 'default' => '', + 'type' => 'option', + 'capability' => 'manage_woocommerce', + 'sanitize_callback' => array( $this, 'sanitize_archive_display' ), + ) + ); + + $wp_customize->add_control( + 'woocommerce_shop_page_display', + array( + 'label' => __( 'Shop page display', 'woocommerce' ), + 'description' => __( 'This controls what is shown on the product archive.', 'woocommerce' ), + 'section' => 'woocommerce_product_grid', + 'settings' => 'woocommerce_shop_page_display', + 'type' => 'select', + 'choices' => array( + '' => __( 'Show products', 'woocommerce' ), + 'subcategories' => __( 'Show categories', 'woocommerce' ), + 'both' => __( 'Show categories & products', 'woocommerce' ), + ), + ) + ); + + $wp_customize->add_setting( + 'woocommerce_category_archive_display', + array( + 'default' => '', + 'type' => 'option', + 'capability' => 'manage_woocommerce', + 'sanitize_callback' => array( $this, 'sanitize_archive_display' ), + ) + ); + + $wp_customize->add_control( + 'woocommerce_category_archive_display', + array( + 'label' => __( 'Default category display', 'woocommerce' ), + 'description' => __( 'This controls what is shown on category archives.', 'woocommerce' ), + 'section' => 'woocommerce_product_grid', + 'settings' => 'woocommerce_category_archive_display', + 'type' => 'select', + 'choices' => array( + '' => __( 'Show products', 'woocommerce' ), + 'subcategories' => __( 'Show categories', 'woocommerce' ), + 'both' => __( 'Show subcategories & products', 'woocommerce' ), + ), + ) + ); + + $wp_customize->add_setting( + 'woocommerce_default_catalog_orderby', + array( + 'default' => '', + 'type' => 'option', + 'capability' => 'manage_woocommerce', + 'sanitize_callback' => array( $this, 'sanitize_default_catalog_orderby' ), + ) + ); + + $wp_customize->add_control( + 'woocommerce_default_catalog_orderby', + array( + 'label' => __( 'Default product sorting', 'woocommerce' ), + 'description' => __( 'This controls the default sort order of the catalog.', 'woocommerce' ), + 'section' => 'woocommerce_product_grid', + 'settings' => 'woocommerce_default_catalog_orderby', + 'type' => 'select', + 'choices' => apply_filters( 'woocommerce_default_catalog_orderby_options', array( + 'menu_order' => __( 'Default sorting (custom ordering + name)', 'woocommerce' ), + 'popularity' => __( 'Popularity (sales)', 'woocommerce' ), + 'rating' => __( 'Average rating', 'woocommerce' ), + 'date' => __( 'Sort by most recent', 'woocommerce' ), + 'price' => __( 'Sort by price (asc)', 'woocommerce' ), + 'price-desc' => __( 'Sort by price (desc)', 'woocommerce' ), + ) ), + ) + ); + $wp_customize->add_setting( 'woocommerce_catalog_columns', array( From 2b2a0016d34b804d89c4e6f8a58939ae06eb9f1e Mon Sep 17 00:00:00 2001 From: Caleb Burks <19caleb95@gmail.com> Date: Mon, 11 Dec 2017 22:36:39 -0600 Subject: [PATCH 3/4] Move early return --- includes/customizer/class-wc-customizer.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/includes/customizer/class-wc-customizer.php b/includes/customizer/class-wc-customizer.php index 1b4de2db21b..430e1e93ace 100644 --- a/includes/customizer/class-wc-customizer.php +++ b/includes/customizer/class-wc-customizer.php @@ -212,9 +212,6 @@ class WC_Customizer { * @param WP_Customize_Manager $wp_customize Theme Customizer object. */ public function add_product_grid_section( $wp_customize ) { - if ( has_filter( 'loop_shop_columns' ) ) { - return; - } $theme_support = get_theme_support( 'woocommerce' ); $theme_support = is_array( $theme_support ) ? $theme_support[0]: false; @@ -309,6 +306,11 @@ class WC_Customizer { ) ); + // The following settings should be hidden if the theme is declaring the values. + if ( has_filter( 'loop_shop_columns' ) ) { + return; + } + $wp_customize->add_setting( 'woocommerce_catalog_columns', array( From a4f9d1e65a28e693735a1f102f6f1ef078b15737 Mon Sep 17 00:00:00 2001 From: Caleb Burks <19caleb95@gmail.com> Date: Mon, 11 Dec 2017 23:42:48 -0600 Subject: [PATCH 4/4] Docs update --- includes/customizer/class-wc-customizer.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/customizer/class-wc-customizer.php b/includes/customizer/class-wc-customizer.php index 430e1e93ace..ba4f5c881fa 100644 --- a/includes/customizer/class-wc-customizer.php +++ b/includes/customizer/class-wc-customizer.php @@ -122,7 +122,7 @@ class WC_Customizer { /** * Sanitize the shop page & category display setting. * - * @return array + * @return string */ public function sanitize_archive_display( $value ) { $options = array( '', 'subcategories', 'both' ); @@ -133,7 +133,7 @@ class WC_Customizer { /** * Sanitize the catalog orderby setting. * - * @return array + * @return string */ public function sanitize_default_catalog_orderby( $value ) { $options = apply_filters( 'woocommerce_default_catalog_orderby_options', array(