Hi, I tried to Replace “Sale” Tag With “Discount Percentage”? (Minion Theme), using the code provided in other answers, but it shows error like this.
my website is: https://babycoo.com.au/
A Shopify store owner using the Minion theme is attempting to replace the standard “Sale” tag with a dynamic discount percentage display on product cards.
Initial Problem:
Troubleshooting Steps:
product.selected_or_first_available_variant to calculate discount percentageUpdated Solution:
card_product.selected_or_first_available_variant instead((compare_at_price - price) / compare_at_price * 100) rounded to 0 decimal placesCurrent Status:
The discussion remains ongoing with the latest code suggestion awaiting implementation and testing. The key issue appears to be using the correct product object reference for collection page contexts.
Hi, I tried to Replace “Sale” Tag With “Discount Percentage”? (Minion Theme), using the code provided in other answers, but it shows error like this.
my website is: https://babycoo.com.au/
Hey @Babycoo ,
Please use below code:
{% assign price = product.selected_or_first_available_variant.price %}
{% assign compare_at_price = product.selected_or_first_available_variant.compare_at_price %}
{% assign discount_percentage = compare_at_price
| minus: price
| times: 100.0
| divided_by: compare_at_price
%}
-{{ discount_percentage | round: 0 }}% off
Thanks,
Ritu
Hello @Babycoo ,
Are you adding this into card-product.liquid ?
@Babycoo ,
Try this code:
{% assign price = card_product.selected_or_first_available_variant.price %}
{% assign compare_at_price = card_product.selected_or_first_available_variant.compare_at_price %}
{% assign discount_percentage = compare_at_price
| minus: price
| times: 100.0
| divided_by: compare_at_price
%}
-{{ discount_percentage | round: 0 }}% off