Woocommerce generally displays only the categories with products on the Shop page. I would like to display all the categories(except Uncategorized) in the Shop Page even if it's empty.
The below displays all the categories including Uncategorized. Is there a way to exclude Uncategorized from that?
add_filter( 'woocommerce_product_subcategories_hide_empty', 'show_empty_categories', 10, 1 );
function show_empty_categories ( $show_empty ) {
$show_empty = true;
return $show_empty;
}
Change the args in the following way
https://github.com/woocommerce/woocommerce/blob/master/includes/wc-template-functions.php#L2479
function my_product_subcategories_arg( $args ) {
$uncategorized = get_option( 'default_product_cat' );
$args['exclude'] = $uncategorized;
$args['hide_empty'] = 0;
return $args;
}
add_filter( 'woocommerce_product_subcategories_args', 'my_product_subcategories_arg', 10, 1 );
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.