Title: Hide menu cart when empty
Last modified: November 17, 2020

---

# Hide menu cart when empty

 *  Resolved [adamparr01](https://wordpress.org/support/users/adamparr01/)
 * (@adamparr01)
 * [5 years, 5 months ago](https://wordpress.org/support/topic/hide-menu-cart-when-empty/)
 * Hi,
 * I’ve been trying for a while to hide the menu cart only when it’s empty. I don’t
   really know any coding but my developers suggested I ask you for the “CSS class
   set indicating the cart is empty or indicating it has a count on the element 
   itself, or on a parent element”.
 * I was hoping you could please help with this so that I can finalise this last
   change on my website. Ideally I’d like to hide the dividing lines above and below
   if possible too.
 * Thanks in advance!
    Adam
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fhide-menu-cart-when-empty%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 5 replies - 1 through 5 (of 5 total)

 *  Plugin Support [Senff – a11n](https://wordpress.org/support/users/senff/)
 * (@senff)
 * [5 years, 5 months ago](https://wordpress.org/support/topic/hide-menu-cart-when-empty/#post-13673006)
 * Hey [@adamparr01](https://wordpress.org/support/users/adamparr01/)
 * The cart (or any parent) does not have a specific CSS class when it’s empty, 
   so it’s not possible to use CSS code to hide it only when there are no items 
   in it.
 * For this, you will need either PHP code, or Javascript.
 *  Thread Starter [adamparr01](https://wordpress.org/support/users/adamparr01/)
 * (@adamparr01)
 * [5 years, 5 months ago](https://wordpress.org/support/topic/hide-menu-cart-when-empty/#post-13673423)
 * Thank you for explaining! Could you possibly suggest the necessary PHP to fix?
 *  [Ief_DR](https://wordpress.org/support/users/ief_dr/)
 * (@ief_dr)
 * [5 years, 5 months ago](https://wordpress.org/support/topic/hide-menu-cart-when-empty/#post-13681680)
 * Hi,
 * I visited your website. The cart is hidden now when it’s empty. How did you do
   that?
 *  Thread Starter [adamparr01](https://wordpress.org/support/users/adamparr01/)
 * (@adamparr01)
 * [5 years, 5 months ago](https://wordpress.org/support/topic/hide-menu-cart-when-empty/#post-13687513)
 * [@ief_dr](https://wordpress.org/support/users/ief_dr/) I added the following 
   PHP to custom-functions.php
 * add_action(‘wp_head’, ‘hook_css’, 99999);
    function hook_css() { // If cart is
   empty hide the item count if(WC()->cart->is_empty()) echo ‘<style type=”text/
   css”> .main-navigation .grimlock-woocommerce-navbar_nav_menu{display:none !important;}
   </style>’; }
 * If you find the right element on yours hopefully it will work for you too.
 *  [Robert Ghetau](https://wordpress.org/support/users/robertghetau/)
 * (@robertghetau)
 * [5 years, 5 months ago](https://wordpress.org/support/topic/hide-menu-cart-when-empty/#post-13763053)
 * Hey [@adamparr01](https://wordpress.org/support/users/adamparr01/) !
 * Thank you for sharing the solution with the others!
 * I’ll go ahead and close the forum thread for now, but please open a new one if
   you have any questions.
 * Warm regards,

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Hide menu cart when empty’ is closed to new replies.

 * ![](https://ps.w.org/woocommerce/assets/icon.svg?rev=3234504)
 * [WooCommerce](https://wordpress.org/plugins/woocommerce/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/woocommerce/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/woocommerce/)
 * [Active Topics](https://wordpress.org/support/plugin/woocommerce/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/woocommerce/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/woocommerce/reviews/)

 * 5 replies
 * 4 participants
 * Last reply from: [Robert Ghetau](https://wordpress.org/support/users/robertghetau/)
 * Last activity: [5 years, 5 months ago](https://wordpress.org/support/topic/hide-menu-cart-when-empty/#post-13763053)
 * Status: resolved