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

  • Can you please share the store URL? so I will check and give you one line CSS solution. – Vikram Kumar Sep 10 at 6:55
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 --> 
| improve this answer | |
  • Thanks for your response. I tried it in subtotal.html but it is always showing counter 0. if the cart has items or not. – Utsav Gupta Sep 10 at 9:10
  • is there override the block or js??? – anant prajapati Sep 10 at 15:16
  • Its HTML file which is "app/design/frontend/Vendor/Theme/Magento_Checkout/web/template/minicart/subtotl.html" – Utsav Gupta Sep 14 at 6:32

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.