In summary, this code iterates through each item in the cart, checks if there are any savings on each item, calculates the total savings across all items, and then displays this total savings amount if there are any savings present in the cart.

{% assign total_saving = 0 %}
{% assign cart_savings = false %}
{% for item in cart.items %}
{% if item.variant.compare_at_price > item.variant.price %}
{% assign cart_savings = true %}
{% assign saving = item.variant.compare_at_price | minus: item.variant.price | times: item.quantity %}
{% assign total_saving = saving | plus: total_saving %}
{% endif %}
{% endfor %}

{% if cart_savings %}
<div class=”totalSavings”>
<p class=”summaryHeading”>Total Savings</p>
<p class=”summaryTotals”><strong>{{ total_saving | money }}</strong></p>
</div>
{% endif %}

Categorized in: