Magento 2.3 Minicart check if subtotal is above value
Pergunta
I want to check inside my /app/design/frontend/theme/theme/Magento_Checkout/web/template/minicart/subtotal/totals.html
file if the subtotal is larger than 29.95.
I want to display some additional text if subtotal is larger or smaller than 29.95. The problem is that it is loaded inside a .html file so I cannot use php for this.
How can I achieve this?
Solução
You can have following knockout code in html file to achieve your desired result.
<!-- ko if: cart().subtotalAmount < 29.95 -->
<span>custom message if subtotal is less then 29.95</span>
<!-- /ko -->
<!-- ko if: cart().subtotalAmount > 29.95 -->
<span>custom message if subtotal is greater then 29.95</span>
<!-- /ko -->
Hope this helps.
Outras dicas
Yash Shah's answer worked for me, but only after I found the right place for the code. I added it inside an existing 'ko' element (I'm not familiar with Knockout).
I edited my subtotal.html from this...
<div class="subtotal">
<span class="label">
<!-- ko i18n: 'Cart Subtotal' --><!-- /ko -->
</span>
<!-- ko foreach: elems -->
<!-- ko template: getTemplate() --><!-- /ko -->
<!-- /ko -->
</div>
...to this...
<div class="subtotal">
<span class="label">
<!-- ko i18n: 'Cart Subtotal' --><!-- /ko -->
</span>
<!-- ko foreach: elems -->
<!-- ko template: getTemplate() --><!-- /ko -->
<!-- ko if: cart().subtotalAmount < 50.00 -->
<span>Message for orders under £50</span>
<!-- /ko -->
<!-- ko if: cart().subtotalAmount > 50.00 -->
<span>Message for orders over £50</span>
<!-- /ko -->
<!-- /ko -->
</div>
Something like this would work in Magento 2.
<!-- ko if: getCartParam('summary_count') > 1 || getCartParam('summary_count') == 0 -->
<span>items</span>
<!-- /ko -->
<!-- ko if: getCartParam('summary_count') == 1 -->
<span>item</span>
<!-- /ko -->