All things Shopify and commerce
Hey! Shopify community, I have created the discounts using discount code. Now i want to get the discounted percentage using liquid and discount code. How i can do that??
This is Amelia from PageFly - Landing Page Builder App
You can calculate the discount percentage based on the original price and the discounted price. Here’s how you can do it:
Calculate the Discount Percentage:
Add the Code to Your Theme:
Insert the Liquid Code:
{% if product.compare_at_price > product.price %} {% assign discount_percentage = 100 | times: (product.compare_at_price | minus: product.price) | divided_by: product.compare_at_price | round %} <span class="discount-percentage">{{ discount_percentage }}% OFF</span> {% endif %}
Customize the Display:
.discount-percentage { color: red; font-weight: bold; }
Example Implementation
Here’s an example of how you might integrate this into a product page:
<div class="product-price"> <span class="original-price">{{ product.compare_at_price | money }}</span> <span class="discounted-price">{{ product.price | money }}</span> {% if product.compare_at_price > product.price %} {% assign discount_percentage = 100 | times: (product.compare_at_price | minus: product.price) | divided_by: product.compare_at_price | round %} <span class="discount-percentage">{{ discount_percentage }}% OFF</span> {% endif %} </div>
You should remember that:
Hope that my solution works for you.
Best regards,
Amelia | PageFly
Please let me know if it works by giving it a Like or marking it as a solution!
➜ Optimize your Shopify store with PageFly Page Builder (Free plan available)
➜ Weekly updated Shopify tutorials on YouTube
All features are available from Free plan. Live Chat Support is available 24/7.
Learn how to build powerful custom workflows in Shopify Flow with expert guidance from ...
By Jacqui May 7, 2025Did You Know? May is named after Maia, the Roman goddess of growth and flourishing! ...
By JasonH May 2, 2025Discover opportunities to improve SEO with new guidance available from Shopify’s growth...
By Jacqui May 1, 2025