How to hide certain categories on the main page of the store, on the pages of ca
-
I need to hide (not disable, the category link should open as usual) certain categories in the list of categories and subcategories:
- 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 );
Viewing 6 replies - 1 through 6 (of 6 total)
Viewing 6 replies - 1 through 6 (of 6 total)
- The topic ‘How to hide certain categories on the main page of the store, on the pages of ca’ is closed to new replies.