In Magento 2.3.5-p1 I want to hide the "Sub Total" div if no items in the cart. Also, if the cart has items then that div will show again. How can I achieve this?

There is a "subtotal.html" file in "web/template/minicart/item/" the file content as below:

<div class="subtotal">
    <span class="label">
        <!-- ko i18n: 'Cart Subtotal' --><!-- /ko -->

    <!-- ko foreach: elems -->
        <!-- ko template: getTemplate() --><!-- /ko -->
    <!-- /ko -->

As this div is updating with a knockout Js, can we place any custom class to that div or any other way? please suggest the quickest solution.

enter image description here

  • Can you please share the store URL? so I will check and give you one line CSS solution. Commented Sep 10, 2020 at 6:55

1 Answer 1


Yes, this code should be coming from .html file. You can set the condition like

  <!-- ko if: cart().subtotal -->
    <span data-bind="html: cart().subtotal" class="counter"></span>
    <!-- /ko -->
    <!-- ko ifnot: cart().subtotal -->
    <span data-bind="html: 0" class="counter">0</span>
    <!-- /ko --> 
  • Thanks for your response. I tried it in subtotal.html but it is always showing counter 0. if the cart has items or not. Commented Sep 10, 2020 at 9:10
  • is there override the block or js??? Commented Sep 10, 2020 at 15:16
  • Its HTML file which is "app/design/frontend/Vendor/Theme/Magento_Checkout/web/template/minicart/subtotl.html" Commented Sep 14, 2020 at 6:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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