- This topic has 5 replies, 3 voices, and was last updated 4 years, 7 months ago by
Leo.
-
AuthorPosts
-
October 28, 2021 at 4:10 am #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:
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.
October 28, 2021 at 5:25 am #1980247David
StaffCustomer SupportHi 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/
October 28, 2021 at 11:21 am #1981106Axel
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 🙂
October 28, 2021 at 1:18 pm #1981260David
StaffCustomer SupportGlad to be of help.
November 3, 2021 at 12:02 pm #1990308Axel
… o.k. drives me nuts, sadly.
davids link above seems to be not bad at all. replacing
categorywithproduct_catgives 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; }November 3, 2021 at 12:33 pm #1990358Leo
StaffCustomer SupportI would recommend posting this kind of question in a general WordPress forum like this:
https://wordpress.stackexchange.com/Hope this helps.
-
AuthorPosts
- You must be logged in to reply to this topic.