You Save xx% (xx$) help please with code for variants

New Member
6 0 0

Hello.

I'd like to add a badge after a price on product page with text You Save xx% (xx$) similar to this page:

https://cortex82.com/collections/all-products/products/pulse-oximeter

I would like my badge to automatically calculate savings percentage from the compare price & sale price for all variant of product, not only for first one.

Can anyone help me with the code I need to add?

I use Debutify theme.

Thank you.

0 Likes
Shopify Expert
2490 417 525

Hi @ivanshmidik 

You can add this code i section=>product-template.liquid

 

<p class="saved_price{% if current_variant.compare_at_price <= current_variant.price %} p_hide{% endif %}">
    {% if current_variant.compare_at_price > current_variant.price %}(You save {{ current_variant.compare_at_price | minus: current_variant.price | money_without_trailing_zeros }}){% endif %}
</p>

Add this css in Asset->theme.scss file at bottom:

 

 

.saved_price { opacity: 0.6; margin-top: -10px; font-size: 15px; }
.p_hide { display: none; }

 

 

Want to modify or custom changes on store hire me.
If helpful then please Like and Accept Solution.
Email: jasoliyabrijesh123@gmail.com
Skype: jasoliya.brijesh
Want to get Free review and advice for sale on store ?? just text me here
0 Likes
New Member
6 0 0

Thank you for the answer, but it only works if there is only one product variant. If there's more than one, it doesn't work. 

0 Likes
Shopify Expert
2490 417 525

This code only work on page load on variants changes you have to make same login in  variants selectCallback function in Js(theme.js) file 

Want to modify or custom changes on store hire me.
If helpful then please Like and Accept Solution.
Email: jasoliyabrijesh123@gmail.com
Skype: jasoliya.brijesh
Want to get Free review and advice for sale on store ?? just text me here
0 Likes