I am using cart.js, and been using it for a long time on my stores. I am working on a count down to free shipping based on the cart.total.price. It should be pretty simple, but I can’t get the #counter and cart.total_price to be updated based on cart update.
{% assign some_number = 50000 | minus: cart.total_price %}
<div data-cart-view>
<span class="cart-count" rv-show="cart.total_price | gt 50000">You qualify for free delivery!</span>
<span class="cart-count" rv-show="cart.total_price | lt 50000">If you spend <span id="counter">{{ 50000 | minus: cart.total_price | money }}</span> more you will qualify for free delivery.</span>
</div>
How may I update #counter based on changes done to the cart? I have tried something like this:
<script type="text/javascript">
$(document).on('cart.requestComplete', function(event, cart) {
$('#counter').html();
});
</script>
2
Answers
It is the ordering of your liquid. Your code:
Reads as take 50000 and minus something formatted as $xx.yy. Instead do the minus first and then apply the money filter. As a guess, in two steps:
You are mixing paradigms.
Your initial code block is liquid. It will be processed server side when the page loads.
Your second block is Javascript. It runs client side when some process updates the cart.
You can: