Total Saving on Cart

New Member
6 0 0

Hello team :)

I added a codee to have the "total saving" under the subtotal in the cart page,t

The total saving is working if : 

1. I have one product

2. If I have different product

But it's not working if for the same product the client has a quantity superior at 1. for exemple if he takes 2 pieces of the same product the "total saving" is always the same :(

can you please help me ? this is the code I have added : 

{% assign savings = 0 %}
{% for item in cart.items %}
  {% if item.variant.compare_at_price > item.variant.price %}
    {% assign difference = item.variant.compare_at_price | minus: item.variant.price %}
    {% assign savings = savings | plus: difference %}
  {% endif %}
{% endfor %}

{% if savings > 0 %}
  <p><span style="color: #339966; font-size: medium;">(You SAVE : {{ savings | money }})</span></p>
{% endif %}   

thanks for your help

0 Likes

Hello there,

I think I got the issue you are facing, that is total savings are only shown correcly if product quantity is 1, and if product quantity increases it will still show savings as per one product.

I think I can help you, you need to add this line  {% assign actualSaving = savings | times: item.quantity %} after this line {% assign savings = savings | plus: difference %} and at last in the span tag edit this (You SAVE : {{ actualSaving | money }})

Let me know if it worked.

Thanks,

Sagar Khadke

Have something to say? Or need to say Hi! just mail me at sagar.khadke03@gmail.com or visit https://sagarkhadke.myshopify.com
0 Likes
New Member
6 0 0

Hello Sagar, 

thanks a lot for your precious help, it's working perfectly :)

 

thanks a lot !!

 

Keivan

0 Likes
New Member
1 0 0

Thanks it worked but now I have a different issue 

 

When I add another product with a quantity of more than 1 the total savings line disappears but the you save remains.

 

But if i have one product multi quantity it shows it clearly only when i add more than 1 other product does it disappear now.

 

@Sagar_Khadke 

0 Likes
New Member
3 0 0

I tried that code but its not working. I made some changes and its working fine.

 

Instead of below line
==
{% assign savings = savings | plus: difference %}
==
Use this
==
{% assign diffSaving = difference | times: item.quantity %}
{% assign savings = savings | plus: diffSaving %}
==

0 Likes
New Member
1 0 0

hello currently im working with the supply theme but now the problem is that whenever i am trying adding 2 pcs of any products. Let's say suppose im buying two pcs olive oils of 2ltr each of MRP: 2,600 and we are giving it to our customers in just 2,080 so, the total saving of 1pc is 520.00 Rs. only but when someone is buying 2 pcs then also the same your saving amount is showing 520.00 is that amount which is still being displayed on the screen.

https://www.swayur.com/collections/festive-season-sale-up-to-20-off-borges/products/extra-light-oliv...

 

0 Likes
Tourist
3 0 0

Tried this, but it's not working when another product is added to cart.

 

Works fine with one product, but doesn't change when another is added.

Any ideas why?

0 Likes
New Member
3 0 0

Let me know what issue you are facing. One thing if you are adding product using ajax then you have to add separate code in JS to update Total savings.

0 Likes