I have an issue In Debut Theme, I would like to display the amount of money saved and percentage of discount for each variant of a product.
I have this script in product-template.liquid :
{% assign amount_saved = current_variant.compare_at_price | minus:current_variant.price | money %}
<p>You saved {{ amount_saved | money }}</p>
<p>-{{ product.selected_or_first_available_variant.compare_at_price | minus: product.selected_or_first_available_variant.price | times: 100.0 | divided_by: product.selected_or_first_available_variant.compare_at_price | money_without_currency | replace: ',', '.' | times: 100 | remove: '.0'}}%</p>
This works fine for the first variant by default! But how can I make it work with other variants? When I select the other variant, the “amount_saved” seems not to update properly.
3
Answers
To show percentage saved with each variant, you can use this Shopify app: https://apps.shopify.com/discount-saved
This is for Cart but maybe you can change to fit product although the code used are wellknown github share.
Calculate discount in percentage:
{% for variant in product.variants %}
Save {{ variant.compare_at_price | minus: variant.price | times: 100.0 | divided_by: variant.compare_at_price | round }}%
{% endfor %}