[Resolved] woocommerce: customize WC-menu-item cart template

Home Forums Support [Resolved] woocommerce: customize WC-menu-item cart template

Home Forums Support woocommerce: customize WC-menu-item cart template

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #1008871
    Inga

    Hi there,

    I’m now searching for hours but I can’t find any template with the HTML of the WC-menu-item. I would like to add a custom hook right after the opening wc-menu-item-tag before the anchor-tag in my child theme.
    There is no woocommerce-template either… What am I missing?

    #1008979
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    That element is filtered into the menu items.

    Where exactly are you wanting to hook into? After the menu item, or inside of it?

    #1010050
    Inga

    Hi Tom,
    thanks for your fast reply, I would like to hook inside the menu-item, right after the opening li-tag.

    #1010258
    Tom
    Lead Developer
    Lead Developer

    Unfortunately there is no hook in that location at the moment. I’ve added a note to look at adding one in GPP 1.9.

    What are you trying to add there?

    #1013460
    Inga

    I created a small conditional logged-in-menu with php (Hi [name], my account, logout) and I want it to be displayed left from the cart. No I inserted it with the inside-navigation hook, but I had to place it with css per “absolute”, so when the cart changes his width there is too much space.
    No sure if there is a better solution…

    #1014070
    Tom
    Lead Developer
    Lead Developer

    Ah, well we filter the wc menu item into the menu, so you can use the same method:

    add_filter( 'wp_nav_menu_items', function( $nav, $args ) {
        if ( 'primary' === $args->theme_location ) {
            return sprintf(
                '%1$s
                <li class="your-menu-item-class">
                    Your menu item code in here
                </li>',
                $nav
            );
        }
    
        return $nav;
    }, 5, 2 );

    Let me know if you need more info ๐Ÿ™‚

    #1017125
    Inga

    Thank you, I’m new to filters and programming in general, so as I inserted your code there was a new menu-point added but I don’t know how to move it inside an existing one (the woocommerce-menu-point) what I originally wanted to do. It has to be inside so that I can place it correctly.

    But now I see that even this won’t help me because in the mobile-version the cart-icon is added in a different way and my code would disappear.

    I will do it with the “inside-navigation”-hook and try to position it as precise as possible with CSS.

    Thank you very much anyway!

    #1017154
    Tom
    Lead Developer
    Lead Developer

    I’ll see if I can add a filter in GPP 1.9 to make it easier to prepend/append items to the menu item ๐Ÿ™‚

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