Title: Remove zero from cart
Last modified: August 31, 2016

---

# Remove zero from cart

 *  Resolved [Jon](https://wordpress.org/support/users/duffydjcoat/)
 * (@duffydjcoat)
 * [10 years ago](https://wordpress.org/support/topic/remove-zero-from-cart/)
 * Hi there. Is it possible to have the cart only showing the item count when there
   is a product in the cart? At the moment, on top of the cart icon it shows “0”(
   zero. Is it possible to change the behaviour, so that the cart only shows the
   item count if there is something in the cart?
 * To be clear I don’t to hide the item count completely, but only when the cart
   has nothing on it.
 * Many thanks.
 * [https://wordpress.org/plugins/woocommerce/](https://wordpress.org/plugins/woocommerce/)

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

 *  Plugin Contributor [Mike Jolley](https://wordpress.org/support/users/mikejolley/)
 * (@mikejolley)
 * [10 years ago](https://wordpress.org/support/topic/remove-zero-from-cart/#post-7406685)
 * Sounds like this output is part of your theme – we don’t show a cart count by
   default.
 *  Thread Starter [Jon](https://wordpress.org/support/users/duffydjcoat/)
 * (@duffydjcoat)
 * [10 years ago](https://wordpress.org/support/topic/remove-zero-from-cart/#post-7406688)
 * Thanks Mike. I’ll try to sort that with them then.
 *  Thread Starter [Jon](https://wordpress.org/support/users/duffydjcoat/)
 * (@duffydjcoat)
 * [10 years ago](https://wordpress.org/support/topic/remove-zero-from-cart/#post-7406762)
 * Hi again Mike,
 * I’ve contacted the guys who created the template and they say didn’t change the
   behaviour at all of woocommerce.
 * I’ve got this as the code:
 * _<?php
    if (class\_exists(‘Woocommerce’)) { //Check if display cart in header
 *  global $woocommerce;
    $cart_url = $woocommerce->cart->get_cart_url(); $cart_count
   = $woocommerce->cart->cart_contents_count; ?> <div class=”header_cart_wrapper”
   > <div class=”cart_count”><?php echo esc_html($cart_count); ?></div> “> </div
   > <?php } ?>
 * Thanks
 *  Plugin Contributor [Mike Jolley](https://wordpress.org/support/users/mikejolley/)
 * (@mikejolley)
 * [10 years ago](https://wordpress.org/support/topic/remove-zero-from-cart/#post-7406763)
 * Exactly -if thats in your theme, it’s outputting the cart count, not WooCommerce.
   Wrap this in a check to see if cart_contents_count > 0.
 *  Thread Starter [Jon](https://wordpress.org/support/users/duffydjcoat/)
 * (@duffydjcoat)
 * [10 years ago](https://wordpress.org/support/topic/remove-zero-from-cart/#post-7406766)
 * Hi Mike,
 * Sorry, I’m lost here 🙂
 * Where to I put that bit of code _cart\_contents\_count > 0_?
 * Thanks again!
 *  Plugin Contributor [Mike Jolley](https://wordpress.org/support/users/mikejolley/)
 * (@mikejolley)
 * [10 years ago](https://wordpress.org/support/topic/remove-zero-from-cart/#post-7406779)
 * Just to be clear **this is part of your theme and the author should be doing 
   a better job to support you.**
 * Because that code is out of date and stinks, here is a better version which does
   what you need:
 *     ```
       <?php
       if ( class_exists( 'woocommerce' ) ) {
            $cart_url = WC()->cart->get_cart_url();
            $cart_count = WC()->cart->get_cart_contents_count();
   
            if ( $cart_count > 0 ) {
                 echo '<div class="header_cart_wrapper">';
                 echo '<div class="cart_count">' . absint( $cart_count ) . '</div>';
                 echo '</div>';
            }
       }
       ```
   
 *  Thread Starter [Jon](https://wordpress.org/support/users/duffydjcoat/)
 * (@duffydjcoat)
 * [10 years ago](https://wordpress.org/support/topic/remove-zero-from-cart/#post-7406805)
 * Hi Mike,
 * Thanks a lot for the help. So, I’ve replaced the code I posted above with the
   new one you gave me, but that didn’t work. I can still see the zero in there…
 * Sorry, I’m not really a tech guy, how you might have already figured 🙁
 * Thanks again and sorry to bother with this.
 *  Plugin Contributor [Mike Jolley](https://wordpress.org/support/users/mikejolley/)
 * (@mikejolley)
 * [10 years ago](https://wordpress.org/support/topic/remove-zero-from-cart/#post-7406853)
 * Can you share a link? The code I provided only outputs if $cart_count > 0.
 *  Thread Starter [Jon](https://wordpress.org/support/users/duffydjcoat/)
 * (@duffydjcoat)
 * [10 years ago](https://wordpress.org/support/topic/remove-zero-from-cart/#post-7406865)
 * Hi Mike,
 * Thanks for the reply. Unfortunately I can’t share the link as I’m still working
   on the site locally…
 * I guess it’s difficult for you to figure out what’s not working without a link..
 *  Plugin Contributor [Mike Jolley](https://wordpress.org/support/users/mikejolley/)
 * (@mikejolley)
 * [10 years ago](https://wordpress.org/support/topic/remove-zero-from-cart/#post-7406868)
 * Correct. Maybe this is also being output after ajax load. Theme may have some
   code in other places.
 *  Thread Starter [Jon](https://wordpress.org/support/users/duffydjcoat/)
 * (@duffydjcoat)
 * [10 years ago](https://wordpress.org/support/topic/remove-zero-from-cart/#post-7406869)
 * Thanks Mike. I’ll take it to them again! Thanks for the input. I’ll report back
   if I can find the solution

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

The topic ‘Remove zero from cart’ 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/)

## Tags

 * [cart](https://wordpress.org/support/topic-tag/cart/)
 * [count](https://wordpress.org/support/topic-tag/count/)
 * [zero](https://wordpress.org/support/topic-tag/zero/)

 * 11 replies
 * 2 participants
 * Last reply from: [Jon](https://wordpress.org/support/users/duffydjcoat/)
 * Last activity: [10 years ago](https://wordpress.org/support/topic/remove-zero-from-cart/#post-7406869)
 * Status: resolved