Sale % not showing the correct percentage when I create variants

Hi community,

I have a problem with SALE % showing the correct amount of sale when I create variant.
For example, I created 2 variant one cost 39.99$ and it has no compare at price. Other variant cost 99.95$ and has compare at price of 159.99$. When I click on that product link and select the second variant instead of saying 37.5% it says 75% discount, so the % calculation is wrong.

This happens everytime I create variant product because as I figured it only calculates correctly the % discount of that first variant not for the rest.

This is the product link https://domisana.com/products/imperial-gold-dining-set

Btw, this % option is not default for my theme I enabled it by pasting some code somewhere, I forgot where it was and now I am stuck at this point, trying to fix it.

Any help is appreciated,
Tomi

Hello @Domisana ,

  1. Seems with variant products it does not price the correct price that’s why show wrong calculation.

  2. There is no callback function to update the sale off, that’s why it’s not working.

Regards
Guleria

Hi @Domisana

Could you show me the code you added to display percentage?

{%- if show_badges -%}
{%- if product.price < product.compare_at_price -%}
{%- assign savings = product.compare_at_price | minus: product.price | times: 100.0 | divided_by: product.compare_at_price | round | append: ‘%’ -%}
SAVE {{ savings }}
{% else %}
{%- if product.price < product.compare_at_price -%}
{%- assign savings = product.compare_at_price | minus: product.price | times: 100.0 | divided_by: product.compare_at_price | round | append: ‘%’ -%}
{{ savings }} OFF
{% else %}
{%- if compare_at_price > price -%}
{% assign discount = compare_at_price | minus: price | times: 100.0 | divided_by: compare_at_price | round %}

{{ discount }}% OFF

{% endif %}

this right here has to change, i checked this is the part where it calculates the % its price.liquid

it has to be coded in a way to calculate sale % for each variant separately not using one variant to compare at price only

Please try to use this code only to check

{% assign discount = compare_at_price | minus: price | times: 100.0 | divided_by: compare_at_price | round %}

{{ discount }}% OFF

Hi @Domisana ,

If you find yourself struggling with your code, consider utilizing an app like the Product Labels and Badges app to streamline the process. This tool can assist you in displaying discount amounts or percentages based on product variants.

Moreover, our technical support team is readily available to assist you. It might be worth giving it a try :hugs:

not working tried it