Hide empty categories menu
-
Hi, I have a problem in my site menu because I can’t hide empty categories and automatically update with product stock. I have also tried various functions but none seem to solve my problem
The page I need help with: [log in to see the link]
-
Hi @filipp0!
Where exactly do you want to hide the empty product categories from? The shop page, the main navigation, the widget?
Additionally, what exact functions have you already tried, so we don’t provide you with something you have already done.
Cheers!
thanks for your reply! I would like to hide the empty product categories in the main menu
I tried this function
add_filter( 'wp_get_nav_menu_items', 'hide_empty_navbar_items', 10, 3 ); function hide_empty_navbar_items ( $items, $menu, $args ) { global $wpdb; $empty = $wpdb->get_col( "SELECT term_taxonomy_id FROM $wpdb->term_taxonomy WHERE count = 0" ); foreach ( $items as $key => $item ) { if ( ( 'taxonomy' == $item->type ) && ( in_array( $item->object_id, $empty ) ) ) { unset( $items[$key] ); } } return $items; }I tried that function but it hides the cart and checkout links in the menu, while empty subcategories remain visible
You can find the working solution here: https://stackoverflow.com/a/64970524/7412323
I tested it and it worked on my website
-
This reply was modified 5 years, 2 months ago by
JeanP.
-
This reply was modified 5 years, 2 months ago by
The topic ‘Hide empty categories menu’ is closed to new replies.