Personalized checkout and custom promotions with Shopify Scripts
Hey there, i'm trying to calculate the saved amount on the total cart items.
It works quite well, but let's say i buy a shoe worth 20$ with 50% off, so that would be 10$.
Now it would say i saved 10$, but when i add a second shoe it does not say i saved 20$, it will still say 10$.
How to fix that?
The part of code is below:
{% 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 | times: item.item_count}}{% endcapture %}
{% assign total_saving = saving | plus: total_saving %}
{% endif %}
{% endfor %}
{{ total_saving | money }} EUR
Solved! Go to the solution
This is an accepted solution.
Fixed it myself right now..
For everyone having the same issue: The new code is below
{% 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 | times: item.quantity}}{% endcapture %}
{% assign total_saving = saving | plus: total_saving %}
{% endif %}
{% endfor %}
{{ total_saving | money }} EUR
(Only thing that changes is "times: item.item_count" -> "times: item.quantity") lol, easy fix :Pd
This is an accepted solution.
Fixed it myself right now..
For everyone having the same issue: The new code is below
{% 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 | times: item.quantity}}{% endcapture %}
{% assign total_saving = saving | plus: total_saving %}
{% endif %}
{% endfor %}
{{ total_saving | money }} EUR
(Only thing that changes is "times: item.item_count" -> "times: item.quantity") lol, easy fix :Pd
Hello , That's a really great idea , but will you please let me know where to add this code ??? Please?? And second thing I want to shown on product card also along with cart " Save 10$ " badge then how can we do that ?
Starting a B2B store is a big undertaking that requires careful planning and execution. W...
By JasonH Sep 23, 2024By investing 30 minutes of your time, you can unlock the potential for increased sales,...
By Jacqui Sep 11, 2024We appreciate the diverse ways you participate in and engage with the Shopify Communi...
By JasonH Sep 9, 2024