A Shopify store owner wants to display percentage discounts next to product prices. Their existing Liquid code briefly appears on page load but then disappears.
Solution provided:
Use updated Liquid code in price.liquid and card-product.liquid files that calculates discount percentage using compare_at_price and price variables
The code formula: (compare_at_price - price) × 100 ÷ compare_at_price, rounded to show “Save X%”
Implementation details:
For Prestige theme: Add code to product-meta.liquid or product-info.liquid for product pages; collection pages can enable this via theme settings
For Dawn theme: Insert code below {% render 'price' around line 207 in the card template
Styling adjustments:
Color changes: Modify “Sale badge” color scheme in theme settings
To display discount inline with price (not below): Add CSS to base.css:
For this I use a code that has worked previously on another theme I was working on. However this time for some reason it doesn’t render, when I load the page I can see it pop-up for 0,5sec and then dissapears. I don’t know why. Does anyone know how to fix this? Thank you for your help!
This code will work on the Prestige theme, but you may need to add code to the product-meta.liquid or product-info.liquid file to display on the product page.
On the collection page, Prestige theme can enable it in your theme settings without adding code.
Can you help me to put the code? the first image is the reference of what we want to achieve on the product page. The second image is from our store. Please let me know what kind of information do you need. This is our website - hashdon.com.
May I know if this code will change the current price? I don’t want the price to be changed. I want to show the label of the percentage off only. Thank you.
Just check. Nice work . Exactly like I have mentioned. But can you make the percentage text in green color?
Also, if you wouldn’t mind, can you provide the screenshot where you placing the code. So I can save it for my reference in the future.