Home / Forums / WoodMart support forum / Hide empty product categories from menu
Home › Forums › WoodMart support forum › Hide empty product categories from menu
Hide empty product categories from menu
- This topic has 3 replies, 2 voices, and was last updated 3 days, 3 hours ago by
Aizaz Imtiaz Awan.
-
AuthorPosts
-
December 30, 2025 at 11:42 am #702641
webdev-4670ParticipantHello everyone,
I have created the main menu from Appearance – Menu and I want to hide the empty product categories from it (only on frontend).I have used a php snippet on functions.php but althought it hides the empty categories, it creates two problems.
1. The non empty category is displayed as top menu (besides Home, Shop, Contact etc instead of submenu to Shop)
2. Shop submenu is some other block/widget – I couldn’t find out – that contains the theme’s default megamenu items.Here is the code:
add_filter( 'wp_get_nav_menu_items', 'nav_remove_empty_category_menu_item',10, 3 ); function nav_remove_empty_category_menu_item ( $items, $menu, $args ) { if ( ! is_admin() ) { global $wpdb; $nopost = $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, $nopost ) ) ) { unset( $items[$key] ); } } } return $items; }I’m also attaching two screenshots withthe wrong and right menu.
Thank you in advance.
Thank you in advance.
Attachments:
You must be logged in to view attached files.December 30, 2025 at 3:50 pm #702685
Aizaz Imtiaz AwanKeymasterHello,
In WoodMart, the main menu is generated by the theme’s Mega Menu, not by the standard WordPress menu structure. That’s why using a global PHP filter breaks the menu hierarchy.
To hide empty product categories without breaking the menu, please do the following instead of using custom code:
Navigate to Appearance > Menus > Edit the HTML Block > Use Product Categories element inside the mega menu and Enable “Hide empty categories” option there.
This way, empty categories will be hidden only on the frontend, and the menu structure/design will remain intact.
Best Regards
December 30, 2025 at 4:46 pm #702687
webdev-4670ParticipantHello,
Thank you for your reply.Is there a relevant documentation? I can’t make it work as I want.
When I edit the html block in Elementor, I add the Product Categories element, but the result i not what I want.I want the aside effect dropdown, but with the empty categories hidden.
Could I possibly edit the megamenu templatw file or something like that?
December 31, 2025 at 8:47 am #702745
Aizaz Imtiaz AwanKeymasterHello,
Please see this screenshot for a better understanding of how the product categories widget will work: https://ibb.co/v6VGQr4W
Alternatively, please follow this video guide and create a mega menu down. Try to use the extra menu list widget to show the custom menu items with a custom URL: https://www.youtube.com/watch?v=ZrQF1yHDXfU
Best Regards,
-
AuthorPosts
Tagged: categories, main menu
- You must be logged in to create new topics. Login / Register