In this article, I’ll show you how to Show count 0 on mini cart when no product is in cart Magento 2. By default, the mini cart does not show a 0 when no products are present. If you want the cart to display 0 by default when it is empty, customization is required.
Let’s do this customization, please follow the below steps to do that:
Show count 0 on mini cart when no product is in cart Magento 2
Step 1: Let’s assume that you have created your custom theme or created child theme if you’re using any paid/free theme. Then you need to override minicart.phtml file from the below path:
Copy from: vendor/magento/module-checkout/view/frontend/templates/cart/minicart.phtml
Paste to: app/design/frontend/vendor/themename/Magento_Checkout/templates/cart/minicart.phtml
If you have already overridden minicart.phtml file using a custom module then do the required changes at that location.
Now, open this file and replace the below code :
From:
<span class="counter-number"><!-- ko text: getCartParam('summary_count') --><!-- /ko --></span>
To:
<!-- ko if: getCartParam(summary_count') -->
<span class="counter-number"><!-- ko text: cart().summary_count --><!-- /ko --></span>
<!-- /ko -->
<!-- ko ifnot: getCartParam('summary_count') -->
<span class="counter-number">0</span>
<!-- /ko -->
Step 2:
After doing these changes, 0 will be there in the mini cart section but will not be visible because Magento has made it invisible if the cart is empty using css. So you need to copy _minicart.less file from the below location:
Copy From: vendor/magento/theme-frontend-luma/Magento_Checkout/web/css/source/module/_minicart.less
Paste to: app/design/frontend/Vendot/themename/Magento_Checkout/web/css/source/module/_minicart.less
Now, open this file and replace below code :
From:
&.empty {
display: none;
}
To:
&.empty {
display: inline-block;
}
Now, you need to deploy the code and check it. Finally, you can see in the screenshot below display count 0 on mini cart when no product is in cart.
I believe this blog makes it easy to understand how to show a count 0 on mini cart when there are no products in the cart in Magento 2. Please feel free to leave a comment on this blog, and I’ll get back to you with a proper solution.
You may also like this: