Reputation: 175
I am trying to update some text in the same way the cart count is automatically updated through the Cart API but I'm not sure where to begin
In this example below based on the conditional I want "Item" or "Items" to change without refreshing the page
<span class="cart-count{% if cart.item_count == 0 %} hide{% endif %}">
(<span data-cart-count>{{ cart.item_count }}</span>{% if cart.item_count > 1 %} <span>ITEMS</span>{% else %} <span>ITEM</span>{% endif %})
</span>
Any Suggestions?
Upvotes: 0
Views: 50
Reputation: 249
Unfortunately this cannot be achieved with liquid as liquid is preprocessed before the page is served. You will need to use JavaScript for this. If your theme is using the Shopify Ajax Api for adding the item to the cart, you could use the JSON response to determine how many items are in the cart, then change the text within the <span></span>
accordingly.
Upvotes: 1