Archived topic
Woocommerce Cart Hide and Display
5 replies · Started by Leon on May 6, 2018
Hi Tom,
May I ask if it's possible to achieve so:
GP has an option to display the cart icon in primary nav. I want it to appear when, and only when a customer has some item in their cart (by then the customer may not have logged in yet).
Say, if they browse and added some item to the cart, the cart icon will then show up where it's showing now in the primary nav.
Thank you
Leon
Hey Leon,
Give this a shot: https://generatepress.com/forums/topic/woocommerce-show-cart-in-primary-menu-if-not-empty/#post-521790
Let me know :)
Hi Tom,
Thank you for the big help. That does work for me (also without the class_exists( 'WooCommerce' ) && ).
The only thing that's not perfect is: I'm using WP Rocket caching plugin. If the customer leaves the cart page before checking out for a page he's visited before (say homepage or any page he's browsed), the cart icon will not show up on those pages)
I guess it's because the caching plugin served a cached page.
Not sure if this is something I should ask for help here or from WP rocket. I still can't think of an ideal way to handle this yet. Caching does speed up the site vividly. But things like this often happen...
Thank again Tom
Leon
Ah yea, I'm not sure if there's anything we can do about that on our end.
It might be worth asking their support - they might have a snippet that clears the cache on new item addition/removal from the cart.
Thank you Tom. I've written to them and will update you when I get something.
Leon
Sounds good :)