Archived topic
Hide cart in menu for logged out users
9 replies · Started by Carsten on July 31, 2022
Hi there, I'm running a member site, and I want to hide Woocommerce cart in menu, for logged out users, since it is not relevant to them.
I'm a GP-PRO user, so using a hook or layout element for this would be obvious.
But I need a function for the cart, is this something you could helm me with?
Thanks!
Hi Carsten,
You can try the snippet shared by David here: https://generatepress.com/forums/topic/hide-cart-icon-for-users-not-logged-in/#post-1196163
Adding PHP reference: https://docs.generatepress.com/article/adding-php/#code-snippets
Let us know how it goes.
Hi Fernando, thanks for leading me to this old topic, the snippet worked.
Is it possible to change the priority order of the menu items so the cart is last?
https://imgur.com/uX00KL7
The other menu items are added by this hook generate_menu_bar_items
Thanks!
To clarify, are all menu bar items added through an element? If so, you should be able to change the priority of the element to change their order.
Otherwise, you might need custom CSS. If you can provide the link to your site, I can try to help you with this.
Hi there, all items except the cart is added through an element with priority 10. The cart is added through
Display cart in menu
option in Customize dashboard.
Thanks for offering help, please let me know if you need access to my site.
Hi Carsten,
Try this CSS:
body:not(.logged-in) .menu-bar-item.wc-menu-item {
display:none;
}
If it doesn't work, please link us to your site.
Hi Ying, from what I can see from the code, this is for hiding the cart for logged out users, right?
I got this solved this using this snippet: https://generatepress.com/forums/topic/hide-cart-icon-for-users-not-logged-in/#post-1196163
My last question was about changing the priority for the cart in relation to the elements already in the header added by an element?
Thanks
Ah sorry, I overlooked it.
Can you try setting 5 as the block element's priority?
If it doesn't work, can you link us to your site?
Hi Ying, it worked!
Thanks for your help
Great! You are welcome :)