How To Show % Discount On A Product - Sense theme

Topic summary

A user working with Shopify’s Sense theme needed help displaying dynamic discount percentages on products, rather than manually entering a fixed value like “33%” for each item.

Solutions provided:

  • prakashVt shared Liquid code that calculates discount percentage by comparing product.compare_at_price to product.price
  • Dan-From-Ryviu provided a more specific solution: editing the price.liquid file and replacing the static sale text with dynamic percentage calculation code
  • This solution was confirmed working by multiple users

Extended troubleshooting:

For users on the Atelier theme, different files needed modification:

  • Edit product-card-badges.liquid to show percentages on collection pages
  • Add code to price.liquid (before the last </div>) to display discount badges on individual product pages

Outcome: The discussion reached full resolution with working code snippets for both the Sense and Atelier themes. Users successfully implemented dynamic discount percentage displays across collection and product pages.

Summarized with AI on October 24. AI used: claude-sonnet-4-5-20250929.

ATT_0-1709614897417.png

ATT_1-1709614930878.png

Hello, as you can see from the screenshots above that I can edit what is shown for products on sale. My question is, what should I enter instead of “33” for the site to calculate the discounted value as I am not willing to make each product on 33% sale.

Hello @ATT_1
You can watch this video to set discount
https://www.youtube.com/watch?v=di2O_H1KRdY&t=25s

Hello @ATT_1

You need to add this liquid code if it is not available on your product page

{% if product.compare_at_price > product.price %}
{% assign discount_percentage = product.compare_at_price | minus: product.price%}
{% assign discount_percentage = discount_percentage | times: 100 %}
{% assign discount_percentage = discount_percentage | divided_by: product.compare_at_price %}

{{ discount_percentage }}% off

{% endif %}

See the above image. I tried and it works well. You may need to apply CSS based on your requirement.

Hi @ATT_1

Dan here from Ryviu: Product Reviews & QA app.

Please visit your Online Store > Themes > Edit code > open price.liquid file, find this line of code

{{ 'products.product.on_sale' | t }}

Replace it with this.

{%- assign percent = product.compare_at_price | minus:product.price | times: 100 | divided_by:product.compare_at_price | round -%}
{{ percent }}% SALE
1 Like

Thank you so much! Things from older forums have changed so much that I could get none to work, but this did it!

Hey, Dan! I’ve tried your suggested method on my store yuneeq.in and thank you, it is working perfectly.

I’ve just changed the SALE to OFF and it is live now.

1 Like

Have a great day ahead.

Hey i am using Atelier theme and i am not able to find this {{ ‘products.product.on_sale’ | t }} line in my price.liquid snippet as there is only 79 line of code it self as this is diffrent theme i guess there if few diffrent thing i have also gone through the code but didnt find any if anyone have any clue kindly help me with that.
thankyou

With Atelier theme, please open product-card-badges.liquid file, find and remove this code

{{ 'content.product_badge_sale' | t }}

Yes, it worked! Thank you so much — I had been trying to fix this for the past two weeks and couldn’t find a solution anywhere. Your guidance really helped me and solved the issue right away.

I truly appreciate your time and support.

1 Like

Happy I could help!!!

If you don’t mind me asking, I just noticed that the sale badge shows only on the product collection page, but not on the individual product page. I’d like it to appear there as well, ideally right after the price section. Could you please suggest which .liquid file I should work on to make that change?

Matcha Powder – The House of Umami you can check this to get clear idea

Please add this code to price.liquid file in snippets before the last </div>

{%- if template.name contains 'product' -%}
  {%- assign percent = selected_variant.compare_at_price | minus:selected_variant.price | times: 100 | divided_by:selected_variant.compare_at_price| round -%}
  {{ percent }}% SALE  
{%- endif -%}

Thank you so much, Sir, for your help! It’s finally done. Thanks!

1 Like

You are very welcome!!!