WC_Shop_Customizer::add_product_catalog_section │ public │ WC 1.0
Product catalog section.
Method of the class: WC_Shop_Customizer{}
Hooks from the method
Returns
null. Nothing (null).
Usage
$WC_Shop_Customizer = new WC_Shop_Customizer(); $WC_Shop_Customizer->add_product_catalog_section( $wp_customize );
- $wp_customize(WP_Customize_Manager) (required)
- Theme Customizer object.
WC_Shop_Customizer::add_product_catalog_section() WC Shop Customizer::add product catalog section code WC 10.5.0
public function add_product_catalog_section( $wp_customize ) {
$wp_customize->add_section(
'woocommerce_product_catalog',
array(
'title' => __( 'Product Catalog', 'woocommerce' ),
'priority' => 10,
'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' => __( 'Choose what to display on the main shop page.', 'woocommerce' ),
'section' => 'woocommerce_product_catalog',
'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' => __( 'Category display', 'woocommerce' ),
'description' => __( 'Choose what to display on product category pages.', 'woocommerce' ),
'section' => 'woocommerce_product_catalog',
'settings' => 'woocommerce_category_archive_display',
'type' => 'select',
'choices' => array(
'' => __( 'Show products', 'woocommerce' ),
'subcategories' => __( 'Show subcategories', 'woocommerce' ),
'both' => __( 'Show subcategories & products', 'woocommerce' ),
),
)
);
$wp_customize->add_setting(
'woocommerce_default_catalog_orderby',
array(
'default' => 'menu_order',
'type' => 'option',
'capability' => 'manage_woocommerce',
'sanitize_callback' => array( $this, 'sanitize_default_catalog_orderby' ),
)
);
/* phpcs:disable WooCommerce.Commenting.CommentHooks.MissingHookComment */
$wp_customize->add_control(
'woocommerce_default_catalog_orderby',
array(
'label' => __( 'Default product sorting', 'woocommerce' ),
'description' => __( 'How should products be sorted in the catalog by default?', 'woocommerce' ),
'section' => 'woocommerce_product_catalog',
'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(
'default' => 4,
'type' => 'option',
'capability' => 'manage_woocommerce',
'sanitize_callback' => 'absint',
'sanitize_js_callback' => 'absint',
)
);
$wp_customize->add_control(
'woocommerce_catalog_columns',
array(
'label' => __( 'Products per row', 'woocommerce' ),
'description' => __( 'How many products should be shown per row?', 'woocommerce' ),
'section' => 'woocommerce_product_catalog',
'settings' => 'woocommerce_catalog_columns',
'type' => 'number',
'input_attrs' => array(
'min' => wc_get_theme_support( 'product_grid::min_columns', 1 ),
'max' => wc_get_theme_support( 'product_grid::max_columns', '' ),
'step' => 1,
),
)
);
// Only add this setting if something else isn't managing the number of products per page.
if ( ! has_filter( 'loop_shop_per_page' ) ) {
$wp_customize->add_setting(
'woocommerce_catalog_rows',
array(
'default' => 4,
'type' => 'option',
'capability' => 'manage_woocommerce',
'sanitize_callback' => 'absint',
'sanitize_js_callback' => 'absint',
)
);
}
$wp_customize->add_control(
'woocommerce_catalog_rows',
array(
'label' => __( 'Rows per page', 'woocommerce' ),
'description' => __( 'How many rows of products should be shown per page?', 'woocommerce' ),
'section' => 'woocommerce_product_catalog',
'settings' => 'woocommerce_catalog_rows',
'type' => 'number',
'input_attrs' => array(
'min' => wc_get_theme_support( 'product_grid::min_rows', 1 ),
'max' => wc_get_theme_support( 'product_grid::max_rows', '' ),
'step' => 1,
),
)
);
}