Site icon MageComp Blog

Magento 2: Show Count 0 on Mini Cart when No Product is in Cart

Show-count-0-on-mini-cart-when-no-product-is-in-cart-In-M2

Hello Magento Friends,

Welcome to Magento 2 “How To” Blog Series by MageComp. Today’s topic is Magento 2: Show Count 0 on Mini Cart when No Product is in Cart.

By default, in Magento 2, if the cart is empty then no product count is displayed on the mini cart. However, to show count 0 for an empty cart, you can accomplish it with customization.

So let’s make a start.

Steps to Show Count 0 on Mini Cart when No Product is in Cart in Magento 2:

To do changes in core files is not a relevant idea so kindly override the core file to the theme.

If there is any custom theme then replace the below code with the code present already.

And if there is no custom theme, you need to override core template files to your theme. 

Step 1: Change in Template file

File path to copy the code from :

vendor\magento\module-checkout\view\frontend\templates\cart\minicart.phtml

Now, open this file and replace the below code from:

<span class="counter-number"><!-- ko text: getCartParam('summary_count') --><!-- /ko --></span>

File path to paste the code: 

app\design\frontend\Themes\Yourtheme\Magento_Checkout\te‌​mplates\cart\minicar‌​t.phtml

Replace the code 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: Also need to make changes in CSS file.

So need to override the below path to your theme folder.

File path to copy from:

vendor\magento\theme-frontend-luma\Magento_Checkout\web\css\source\module\_minicart.less

Now, open this file and replace the below code from:

&.empty {

display: none;

}

File path to paste : 

app\design\frontend\Themes\Yourtheme\Magento_Checkout\web\css\source\module\_minicart.less

Replace the code to:

&.empty {

display: inline-block;

}

On you are completed with the above steps, check the results in the frontend of the Magento 2 store. The cart will show count 0 on the mini cart as shown in the figure.

Conclusion:

Hence, accordingly, you can Show Count 0 on Mini Cart when No Product is in Cart in Magento 2. If you face any challenges, feel free to mention them in the comment section and I will be right there to solve them for you. Do share the article with your Magento 2 friends and stay in touch with us.

Happy Coding!

Exit mobile version