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. 

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.

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

add_filter('astra_woo_header_cart_total', 'remove_cart_count');
function remove_cart_count( $default){
if(0 == WC()->cart->get_cart_contents_count()){
return false;
}else{
return $default;
}
}

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.

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注