Home › Forums › Support › WooCommerce Show Cart In Primary Menu If Not Empty This topic has 10 replies, 4 voices, and was last updated 5 years, 11 months ago by Tom. Viewing 11 posts - 1 through 11 (of 11 total) Author Posts March 16, 2018 at 12:21 am #521286 Fahmi Hi! I need some help. How to show Cart in Primary Menu only if the cart not empty? Having Cart menu item there when it empty not really does anything. Therefore it would be nice to hide it when the cart is empty. Thank you. March 16, 2018 at 10:41 am #521790 TomLead Developer Lead Developer Hi there, Give this PHP a try: add_filter( 'generate_woocommerce_menu_item_location', 'tu_hide_empty_cart_icon' ); function tu_hide_empty_cart_icon( $location ) { if ( class_exists( 'WooCommerce' ) && sizeof( WC()->cart->get_cart() ) > 0 ) { return $location; } return 'none'; } Let me know π March 16, 2018 at 12:08 pm #521868 Fahmi I am not sure why. But the code would work as intended when I remove class_exists( ‘WC’ ) &&. Now with your help, I got it working. Thank you Tom. March 16, 2018 at 9:48 pm #522122 TomLead Developer Lead Developer You’re welcome! March 30, 2018 at 3:24 am #535972 Bertram Hi The above (also leaving out class_exists( βWCβ ) &&) worked for me on desktop, however, the cart is not hiding on mobile when it’s empty. Is there a way to achieve the same function on mobile as well? TIA (Generate Press Premium 1.6) March 30, 2018 at 10:41 pm #536793 TomLead Developer Lead Developer It should work everywhere. Can you link me to your site? March 31, 2018 at 2:17 am #536886 Bertram It’s a new website (WIP), so it’s currently in maintenance mode. I have created a subscriber login to acces: How it’s showing: https://imgur.com/PEIm3j2 How I’d like it to look (cart disabled in customiser): https://imgur.com/GORYRZD My PHP code: https://imgur.com/PJBfBiV I’ve put the php code in ‘wp-head’ in GP hooks, I’m not sure if that is what’s causing the problem. March 31, 2018 at 9:01 am #537216 TomLead Developer Lead Developer Seems like a bug. I’ll get it fixed in the next version. Thank you! March 31, 2018 at 3:44 pm #537452 Bertram Okay good to hear, thank you π May 6, 2018 at 10:46 am #568982 Kim Is this already working on mobile? Many thanks π May 6, 2018 at 9:34 pm #569250 TomLead Developer Lead Developer Not yet – this fix will be in 1.6.3 π Author Posts Viewing 11 posts - 1 through 11 (of 11 total) You must be logged in to reply to this topic. Log In Username: Password: Keep me signed in Log In