Update Message When Cart Quantity Changes

Hello,

I’m using the Sense theme and have a simple message in a liquid section that includes the number of items in the cart using “cart.item_count”. How do I enable this to update (without refreshing the page) when another item is added or the quantity is increased?

Hello,

I am San from MS Web Designer.

After reviewing the sense theme demo preview, we confirmed that the cart quantity updates in real-time without requiring a page refresh. Please make sure you are using the latest version of the theme. Let me know where you would like the number of items added to the cart to be displayed.

Hope this helps.

Do let me know in case of any concerns.

Regards,

San

Thank you for the reply. Apologies for the confusion, the issue is not with the cart quantity itself updating. On my cart page, I’ve added a “Custom Liquid” section containing a message that needs to update when the cart quantity changes. Here’s an example of the code in the liquid section:

{% if cart.item_count > 0 %} This order contains {{ cart.item_count }} items. {% else %} You have no items in your cart! {% endif %}

How do I ensure that “{{ cart.item_count }}” updates, without refreshing the page, when the cart quantity changes?

Hey @Xenythian , no way, I coded this just yesterday lmao. Heres the code I used, it works:

{% assign cart_item_count = cart.item_count %}

{% case cart_item_count %}
  {% when 1 %}
    {% assign discount_message = "No discount available for single item." %}
  {% when 2 %}
    {% assign discount_message = "You save 10% with two items in your cart!" %}
  {% else %}
    {% assign discount_message = "Great choice! You've unlocked a special discount!" %}
{% endcase %}

  

{{ discount_message }}

Hope that helped and please mark as solved and like if I helped you :slightly_smiling_face:

Forgot to say. Paste that in a snippet and name it cart-discount and go to the snippet cart-drawe.liquid and paste

{% render 'cart-discount' %}

where you want to add it :wink: