Merge pull request #18108 from WPprodigy/more-customizer-things

Move some display settings to the customizer
This commit is contained in:
Claudiu Lodromanean 2017-12-12 07:40:35 -08:00 committed by GitHub
commit 07b40a6d99
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 125 additions and 52 deletions

View File

@ -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' ),

View File

@ -110,6 +110,44 @@ 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' );
}
/**
* Sanitize the shop page & category display setting.
*
* @return string
*/
public function sanitize_archive_display( $value ) {
$options = array( '', 'subcategories', 'both' );
return in_array( $value, $options ) ? $value : '';
}
/**
* Sanitize the catalog orderby setting.
*
* @return string
*/
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.
*
@ -174,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;
@ -185,11 +220,97 @@ 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',
)
);
$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' ),
) ),
)
);
// 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(