How To

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

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!

Click to rate this post!
[Total: 4 Average: 5]
Dhiren Vasoya

Dhiren Vasoya is a Director and Co-founder at MageComp, Passionate 🎖️ Certified Magento Developer👨‍💻. He has more than 9 years of experience in Magento Development and completed 850+ projects to solve the most important E-commerce challenges. He is fond❤️ of coding and if he is not busy developing then you can find him at the cricket ground, hitting boundaries.🏏

Recent Posts

What are Net Sales? How to Calculate Your Net Sales?

In the world of business, understanding financial metrics is crucial for making informed decisions and…

2 days ago

Magento 2 Extensions Digest April 2024 (New Release & Updates)

Welcome to the MageComp Monthly Digest, where we bring you the latest updates, releases, and…

2 days ago

The ABCs of Geofencing: Definition, Features and Uses

In this era, businesses are always on the lookout for ways to engage with their…

3 days ago

How to Delete Product Variant in a Shopify Remix App using GraphQL Mutations?

Managing a Shopify store efficiently involves keeping your product catalog organized. This includes removing outdated…

4 days ago

6 Innovative Tools Revolutionizing E-Commerce Operations

E-commerce has transformed the way consumers shop for products and services and interact with businesses.…

6 days ago

How Upcoming Cookie Changes Will Affect Your E-commerce Website?

The e-commerce world is constantly in flux. New tech and strategies emerge daily to help…

6 days ago