Home › Forums › WoodMart support forum › How to hide empty categories?
How to hide empty categories?
- This topic has 5 replies, 4 voices, and was last updated 5 years, 11 months ago by
Artem Temos.
Viewing 6 posts - 1 through 6 (of 6 total)
-
AuthorPosts
-
March 22, 2018 at 10:53 am #48077
LateefuddienParticipanthttps://i.gyazo.com/ecb0faf6e29edbe59f3c49c957fe961b.png
Please tell me how to hide these empty categories?
March 22, 2018 at 12:12 pm #48085
Eric WatsonParticipantHello,
Try to add following code snippet to the functions.php file in your child theme
function woodmart_product_categories_nav() { global $wp_query, $post; $show_subcategories = woodmart_get_opt( 'shop_categories_ancestors' ); $show_categories_neighbors = woodmart_get_opt( 'show_categories_neighbors' ); $list_args = array( 'taxonomy' => 'product_cat', 'hide_empty' => true ); // Menu Order $list_args['menu_order'] = false; $list_args['menu_order'] = 'asc'; // Setup Current Category $current_cat = false; $cat_ancestors = array(); if ( is_tax( 'product_cat' ) ) { $current_cat = $wp_query->queried_object; $cat_ancestors = get_ancestors( $current_cat->term_id, 'product_cat' ); } $list_args['depth'] = 5; $list_args['child_of'] = 0; $list_args['title_li'] = ''; $list_args['hierarchical'] = 1; $list_args['show_count'] = woodmart_get_opt( 'shop_products_count' ); $list_args['walker'] = new WOODMART_Walker_Category(); $class = ( woodmart_get_opt( 'shop_products_count' ) ) ? 'has-product-count' : 'hasno-product-count'; $shop_link = get_post_type_archive_link( 'product' ); include_once( WC()->plugin_path() . '/includes/walkers/class-product-cat-list-walker.php' ); if( is_object( $current_cat ) && !get_term_children( $current_cat->term_id, 'product_cat' ) && $show_subcategories && !$show_categories_neighbors ) return; echo '<div class="woodmart-show-categories"><a href="#">' . esc_html__('Categories', 'woodmart') . '</a></div>'; echo '<ul class="woodmart-product-categories ' . esc_attr( $class ). '">'; echo '<li class="cat-link shop-all-link"><div class="category-nav-link"><a href="' . esc_url( $shop_link ) . '"> <span class="category-summary"> <span class="category-name">' . esc_html__('All', 'woodmart') . '</span> <span class="category-products-count"> <span class="cat-count-label">' . esc_html__('products', 'woodmart') . '</span> </span> </span> </a></div></li>'; if( $show_subcategories ) { woodmart_show_category_ancestors(); } else { wp_list_categories( $list_args ); } echo '</ul>'; }
Kind Regards
XTemos StudioMarch 22, 2018 at 12:53 pm #48098
LateefuddienParticipantThank you, it works
March 22, 2018 at 1:02 pm #48100
Eric WatsonParticipantYou are welcome!
April 2, 2019 at 1:57 pm #116450
VladDascaluParticipantI have the same problem. But this doesn’t make any changes on my menu. Is another way to hide the empty categories?
April 3, 2019 at 5:56 am #116547
Artem TemosKeymasterHello,
Please, send us your admin access and a screenshot where you added the code.
Regards
-
AuthorPosts
Viewing 6 posts - 1 through 6 (of 6 total)
- You must be logged in to create new topics. Login / Register