2

Basically i want to show count on cart when no product is in cart.

enter image description here

1
  • Let me know if it'll not working for you Nov 13 '19 at 7:13
6

You need to override minicart.phtml in your theme on below path :

Copy From

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

Paste To

app/design/frontend/{Vendor}/{themename}/Magento_Checkout/te‌​mplates/cart/minicar‌​t.phtml

Now, replace 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 -->

Hope, It will helpful for you.

Also update CSS: .minicart-wrapper .action.showcart .counter.qty.empty { display: inline-block; }

3
  • 1
    The right way to do it. +1 for the answer.
    – Sumit
    Nov 13 '19 at 6:54
  • <!-- ko if: getCartParam('summary_count') --> missing comma before summary_count
    – Nirav Bhoi
    Apr 9 '21 at 12:22
  • Not needed. It's perfect. Apr 9 '21 at 12:28
1

You can add below line in your CSS file

.counter.empty{display: block !important;}

and run below commands

php bin/magento setup:upgrade
php bin/magento cache:clean
php bin/magento cache:flush

Hope this will work for you!

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.