How To Replace "Sale" Tag With "Discount Percentage"? (Minion Theme)

Babycoo
Tourist
7 0 2

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. Image_20240216234500.png

my website is: https://babycoo.com.au/

BabyCoo Australia - Your Local Top Choice for Premium Baby Products with affordable price! Explore our eco-friendly toys, high-quality baby carriers, Toddler Balance Bike and stylish nursery essentials. Find the perfect gifts. BabyCoo - Where Little Wonders Meet Big Adventures!
Replies 4 (4)

Ritu-25
Shopify Partner
129 26 15

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
%}
<span class="percent-count">-{{ discount_percentage | round: 0 }}% off</span>

 

Thanks, 

Ritu 

If helpful then please Like and Accept Solution.
You can directly PM.
Email Me : nayakritu.2506@gmail.com
Babycoo
Tourist
7 0 2

Hi, 

 

It shows this errorImage_20240219165141.png

BabyCoo Australia - Your Local Top Choice for Premium Baby Products with affordable price! Explore our eco-friendly toys, high-quality baby carriers, Toddler Balance Bike and stylish nursery essentials. Find the perfect gifts. BabyCoo - Where Little Wonders Meet Big Adventures!
Ritu-25
Shopify Partner
129 26 15

Hello @Babycoo , 

Are you adding this into card-product.liquid ?

 

 

If helpful then please Like and Accept Solution.
You can directly PM.
Email Me : nayakritu.2506@gmail.com
Ritu-25
Shopify Partner
129 26 15

@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
%}
<span class="percent-count">-{{ discount_percentage | round: 0 }}% off</span>
If helpful then please Like and Accept Solution.
You can directly PM.
Email Me : nayakritu.2506@gmail.com