Home Forums WoodMart support forum Hide empty product categories from menu

Hide empty product categories from menu

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #702641

    webdev-4670
    Participant

    Hello 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.
    #702685

    Hello,

    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

    #702687

    webdev-4670
    Participant

    Hello,
    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?

    #702745

    Hello,

    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,

Viewing 4 posts - 1 through 4 (of 4 total)