How To Hide Quantity Number When the Woocommerce Cart Is Empty?

How To Hide Quantity Number When the Woocommerce Cart Is Empty?

Astra’s Header Footer Builder comes with the WooCommerce Cart element that allows you to add the mini-cart to your header. By default, the mini-cart displays a number of items added to the cart together with the icon.

The mini-cart will show the number “0” until the first product is added to the cart. 

WooCommerce Mini-Cart

In case you would like to hide this number, you can do it by adding a custom code (filter). Adding the filter will hide the number of products while the mini-cart is empty.

Filter to Hide the Quantity Number When Cart I Empty

To do this, you would need to add the following filter to the functions.php file of your Child Theme:

add_action('wp_footer', 'hide_cart');
    function hide_cart() {
        if(WC()->cart->get_cart_contents_count() == 0)
        echo '<style type="text/css">.ast-site-header-cart .ast-addon-cart-wrap i.astra-icon:after{display:none}</style>';
    }
add_filter( 'woocommerce_product_categories_widget_args', 'woo_product_cat_widget_args' );

If you don’t have your Child Theme installed, please check this article on how to do it.

If you are not sure how to add this code, please check this article

Was this doc helpful?
What went wrong?

We don't respond to the article feedback, we use it to improve our support content.

On this page

Take the First Step Toward Success Now.

You’re backed by an amazing team and a risk-free money-back guarantee!

Download is Just A Click Away!

Enter your email address and be the first to learn about updates and new features.

This field is required.

REWIND

YEAR IN REVIEW

Scroll to Top
Now choose your preferred
page builder addon
Choose your preferred page builder addon

Download is Just A Click Away!

Enter your email address and be the first to learn about updates and new features.

Download Free Astra Theme - Modal Popup Form