Site logo

[Support request] GP simple mega menu with dynamic woo subcategories?

Home Forums Support [Support request] GP simple mega menu with dynamic woo subcategories?

Home Forums Support GP simple mega menu with dynamic woo subcategories?

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #1980128
    Axel

    hi there,

    actually trying to resolve a ‘problem’ with the simple mega menu we buildt with the GP css.
    works great, BUT:
    the customer now often changes the woo subcategories which causes a lot of work to update the menu every time …

    so it would be ideal to have the menu grandchilds for the subcategories loaded dynamically for appropriate auto update.
    menu is buildt like so with five childs in the simple mega:

    menu

    the child level is defined manually for the demanded main categories – this is o.k.
    but the grandchilds should reflect all the subcategories of the parent level on an automatic basis if possible in any way.

    tried a few approaches including mega menu plugins and code but nothing seems to work anyway near so far.

    so – any idea or hint to get this done in a proper and sleak way???

    thanks for hints and help in advance.

    #1980247
    David
    Staff
    Customer Support

    Hi there,

    there were a few plugins that did this but they’re all out of date…

    Heres an article which gives you the basics of auto adding them, but it would require custom development to fit Woocommerce and your particular need … but gives a good starting point:

    https://www.paulchinmoy.com/adds-sub-categories-sub-menu-under-parent-category-menu-item/

    #1981106
    Axel

    hi david,

    thanks for the hint (link) – although it looks somewhat similar to an already tested approach…
    i’ll try to dig into it.

    yes – theres a few plugins that are eighter seemingly outdatet, dont work very well or are bloating the code awfully.
    surprised anyway that theres no proper buildt in way to accomplish this.

    thanks – i’ll be back on occasion 🙂

    #1981260
    David
    Staff
    Customer Support

    Glad to be of help.

    #1990308
    Axel

    … o.k. drives me nuts, sadly.

    davids link above seems to be not bad at all. replacing category with product_cat gives back “no categories” in the expected places within the menu – so it basically works …

    but cant bypass this. eighter it gives the “no categories” text or nothing at all.
    assuming theres a call for the wrong woo terms somewhere. but my php is far too limited to get over it.

    anybody out there who has more ideas than me? or solved this problem somehow?

    this is the actual code that gives the “no categories” line:

    add_filter( 'walker_nav_menu_start_el', 'xx_add_subcategories_under_parent_category', 10, 4 );
    function xx_add_subcategories_under_parent_category( $item_output, $item, $depth, $args ) {
    	if( $args->theme_location == 'primary' && $item->object === 'product_cat' && $item->type === 'taxonomy' ) {
    		$sub_cats = wp_list_categories( [ 'echo' => 0, 'hide_empty' => 1, 'child_of' => $item->object_id, 'title_li' => '' ] );
    		if( ! empty( $sub_cats ) ) {
    			$class = "menu-item menu-item-object-{$item->object} menu-item-type-{$item->type}";
    			$sub_cats = preg_replace( '#<ul\sclass=([^>]*)>#', '<ul class="sub-menu">', $sub_cats );
    			$sub_cats = preg_replace( '#<li\sclass="([^>]*)">#', '<li class="' . $class . ' $1">', $sub_cats );
    			$item_output .= '<ul class="sub-menu">' . "\n";
    			$item_output .= $sub_cats;
    			$item_output .= '</ul>' . "\n";
    		}
    	}
    
    	return $item_output;
    }
    #1990358
    Leo
    Staff
    Customer Support

    I would recommend posting this kind of question in a general WordPress forum like this:
    https://wordpress.stackexchange.com/

    Hope this helps.

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.