- This topic has 5 replies, 3 voices, and was last updated 1 year, 6 months ago by
Tom.
-
AuthorPosts
-
December 5, 2020 at 2:52 am #1568216
Daniel
Hi!
Since version 3 of Generatepress the woocommerce cart icon is out of #primary-menu div.
I have made some customizations in the menu of my web using flexbox so that all the li elements inside the main menu occupy the same horizontal space. This change does not affect the cart button because it is out of the main menu.
My question is, could I make the cart be a li element inside the main menu again in order to apply the same flexbox rule as the rest of the menu items?
Thanks!
DanielDecember 5, 2020 at 5:04 am #1568296David
StaffCustomer SupportHi there,
can you provide a link to your site so i can see the issue, maybe a simple CSS fix for that.
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/December 5, 2020 at 5:48 am #1568325Daniel
Hi David,
I can’t provide a link to the website because it is not online yet, but I doubt it can be fixed with css only.
This is the html code for the menu:
<div id="primary-menu" class="main-nav"> <ul id="menu-menu-principal" class=" menu sf-menu"> <li><a href="" aria-current="page">ITEM 1</a></li> <li><a href="" aria-current="page">ITEM 2</a></li> <li><a href="" aria-current="page">ITEM 3</a></li> <li><a href="" aria-current="page">ITEM 4</a></li> </ul> </div> <div class="menu-bar-items"> <span class="menu-bar-item wc-menu-item has-items"> <a href="" class="cart-contents shopping-cart has-svg-icon">CART ICON</a> </span> </div>
As you can see, the Cart Icon is outside the #primary-menu.
I added the property: flex=1 to #primary-menu li items in order to make them the same width regardless of their content but it can’t be applied to the cart icon because it isn’t a child element of the same flex container as the rest of the menu.I could declare a fixed width for all the menu items and the cart but then I’ll lose the responsive behaviour when the viewport shrinks.
December 5, 2020 at 11:59 am #1568732Tom
Lead DeveloperLead DeveloperHi there,
Yes, you can filter the menu items like this:
add_filter( 'wp_nav_menu_items', function( $items, $args ) { if ( 'primary' === $args->theme_location ) { $has_items = false; if ( ! WC()->cart->is_empty() ) { $has_items = 'has-items'; } return sprintf( '%1$s <li class="wc-menu-item menu-item-align-right %3$s %4$s"> %2$s </li>', $items, generatepress_wc_cart_link(), is_cart() ? 'current-menu-item' : '', $has_items ); } return $items; }, 10, 2 );
Hope this helps ๐
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentDecember 6, 2020 at 12:42 am #1569013Daniel
Great! That’s just what I needed.
Thank you so much for your help.December 6, 2020 at 11:58 am #1569585Tom
Lead DeveloperLead DeveloperYou’re welcome ๐
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-development -
AuthorPosts
- You must be logged in to reply to this topic.