Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save raihan004/133b534a15ac07d2ee488140267bea14 to your computer and use it in GitHub Desktop.
Save raihan004/133b534a15ac07d2ee488140267bea14 to your computer and use it in GitHub Desktop.
Shopify - Show total savings on cart page
{% assign total_saving = 0 %}
{% for item in cart.items %}
{% if item.variant.compare_at_price > item.variant.price %}
{% capture saving %}{{ item.variant.compare_at_price | minus: item.variant.price }}{% endcapture %}
{% assign total_saving = saving | plus: total_saving %}
{% endif %}
...rest of cart code within for loop
{% endfor %}
Display saving:
Saving - {{ total_saving | money }}
@raihan004
Copy link
Author

#quantity support
{% assign total_saving = 0 %}
{% for item in cart.items %}
{% if item.variant.compare_at_price > item.variant.price %}
{% capture saving %}{{ item.variant.compare_at_price | minus: item.variant.price }}{% endcapture %}
{% if item.variant.compare_at_price > item.variant.price %}
{% assign saving = item.variant.compare_at_price | minus: item.variant.price | times: item.quantity %}
{% assign total_saving = saving | plus: total_saving %}
{% endif %}
{% endif %}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment