0

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 -->
    </span>

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

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

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

1 Answer 1

0

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 --> 
3
  • Thanks for your response. I tried it in subtotal.html but it is always showing counter 0. if the cart has items or not. Sep 10, 2020 at 9:10
  • is there override the block or js??? Sep 10, 2020 at 15:16
  • Its HTML file which is "app/design/frontend/Vendor/Theme/Magento_Checkout/web/template/minicart/subtotl.html" Sep 14, 2020 at 6:32

Your Answer

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

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