skip to Main Content

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


  1. To show percentage saved with each variant, you can use this Shopify app: https://apps.shopify.com/discount-saved

    Login or Signup to reply.
  2. This is for Cart but maybe you can change to fit product although the code used are wellknown github share.

    Login or Signup to reply.
  3. 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 %}

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search