Woocommerce. How to hide some categories and subcategories on the shop main page, catalog pages (archive, categories and subcategories pages)
Woocommerce. How to hide some categories and subcategories on the shop main page, catalog pages (archive, categories and subcategories pages)
I need to hide (not disable, the category link should open as usual) certain categories in the list of categories and subcategories Woocommerce on the shop main page, catalog pages (archive, categories and subcategories pages):
If there are no products in this category
If all products in this category are Out of stock
If all products in this category are Catalog visibility: Hidden
I found a solution for this for the main store page, however, on the product category and archive counters, this solution completely removes all subcategories.
function hide_empty_categories( $terms, $taxonomies, $args ) {
$new_terms = array();
foreach ( $terms as $key => $term ) {
if ( is_object( $term ) ) {
if ( $term->count > 0 ) {
$new_terms[] = $term;
}
}
}
return $new_terms;
}
add_filter( 'get_terms', 'hide_empty_categories', 10, 3 );
PS. There is no problem in the widget of categories and subcategories of products that are in the sidebar. There, the standard settings hide such categories, the problem is in the main place of displaying categories and subcategories
Has anyone found the solution to set the product Catalog visibility: Hidden? How to use it in a way that it affected the categories (and not just the product)?
I contacted Woocommerce support, where they told me that there are no standard solutions for this. I also tried to use different codes, the one given above, but it does not work correctly
Turbo Multi-language Translator
Make the better internet purchasing globaly
Turbosify SEO Speed Booster
5.0 (7)•Free plan available
Get better conversions by improving store loading speed
Installed
Turbo Multi-language Chat - AI Customer service in one hand