Have your say in Community Polls: What was/is your greatest motivation to start your own business?

Make dynamic sale badge

Solved

Make dynamic sale badge

robertsolcan
Excursionist
39 0 4

I want for this badge to be more dynamic, instead of just the "%" I want to show something like " 45% OFF"WhatsApp Image 2024-11-05 at 10.39.32.jpeg

Do you think you can help me with that?

Accepted Solution (1)

GTLOfficial
Shopify Partner
658 140 133

This is an accepted solution.

Hello @robertsolcan 

Go to online store ----> themes ----> actions ----> edit code ----> snippets ----> card-product.liquid ---> line number 140
add this code at the end of the file and save.
1) Collection page:-

{% assign saving = card_product.compare_at_price
| minus: card_product.price
| times: 100
| divided_by: card_product.compare_at_price
%}
{{ saving | append: '% OFF' }}

 

Go to online store ----> themes ----> actions ----> edit code ----> snippets ---> price.liquid ---> line number 127
2) Product page:-

{% assign saving = product.compare_at_price
| minus: product.price
| times: 100
| divided_by: product.compare_at_price
%}
{{ saving }} {{ 'products.product.on_sale' | t }}

If this was helpful, hit the like button and accept the solution.
Thanks

- Buy me a Pizza
- If helpful then please Like and Accept Solution.
- Want to modify or custom changes or bug fix on the store Hire me. GTL web solutions
- Want Complete Storefront: Send an email ⇨- Email: info@gtlofficial.com - Skype: ritesh_27dh

View solution in original post

Replies 5 (5)

Fitfusiongear
New Member
4 0 0


ChatGPT said:
ChatGPT
Hi there!

I understand that you want to make the discount badge more dynamic, showing something like "45% OFF" instead of just the percentage symbol. This is definitely possible, but it would require some adjustments to your theme's code, specifically in how the discount is calculated and displayed.

I'd be happy to help guide you through the process or assist in making these changes for you. If you'd like, we can discuss your requirements in more detail and go over the best approach to implement this.

Feel free to reach out to schedule a time, and we can dive into the solution together

tobebuilds
Shopify Partner
477 34 128

Hi Robert,

 

In Liquid, a `variant` has these fields: `price` and `compare_at_price`.

 

https://shopify.dev/docs/api/liquid/objects/variant

 

Keep in mind that `compare_at_price` may be zero. You don't want to divide by zero, so you'll need an if statement to check for that.

 

You can try something like:

 

{% if variant.compare_at_price > 0 and variant.compare_at_price > variant.price %}
{{ variant.compare_at_price | minus:variant.price | divided_by: variant.compare_at_price | times: 100 }}% OFF
{% endif %}

 

Hope this helps,

Tobe

Founder, Regios Discounts app (4.9 stars, 68 reviews, Built for Shopify)
- Custom discounts made simple
- "Just about any discount you'll ever need"
- Built by an ex-Google software engineer

Amanda_Fordeer
Shopify Partner
156 10 32

Hi @robertsolcan

You can try the Product Labels & Badges app and use the variables feature (free), also known as dynamic text.

 

Amanda_Fordeer_0-1730954863795.png

 

If you find my suggestion helpful, please give it a like or mark it as a solution!
And discover more approaches to:
Streamline invoicing process Boost sales with labels & badges Add social proofs & create FOMO
Or get valuable updates and private deals regarding Shopify here.

GTLOfficial
Shopify Partner
658 140 133

This is an accepted solution.

Hello @robertsolcan 

Go to online store ----> themes ----> actions ----> edit code ----> snippets ----> card-product.liquid ---> line number 140
add this code at the end of the file and save.
1) Collection page:-

{% assign saving = card_product.compare_at_price
| minus: card_product.price
| times: 100
| divided_by: card_product.compare_at_price
%}
{{ saving | append: '% OFF' }}

 

Go to online store ----> themes ----> actions ----> edit code ----> snippets ---> price.liquid ---> line number 127
2) Product page:-

{% assign saving = product.compare_at_price
| minus: product.price
| times: 100
| divided_by: product.compare_at_price
%}
{{ saving }} {{ 'products.product.on_sale' | t }}

If this was helpful, hit the like button and accept the solution.
Thanks

- Buy me a Pizza
- If helpful then please Like and Accept Solution.
- Want to modify or custom changes or bug fix on the store Hire me. GTL web solutions
- Want Complete Storefront: Send an email ⇨- Email: info@gtlofficial.com - Skype: ritesh_27dh

Ankit6
Shopify Partner
47 3 3

Hi @robertsolcan If you are looking to display multiple badges like percentage sales, simple low-stock, sale, out-of-stock text badges, and custom Image-based Badges on your store, you can use the Prime Badges Labels & Stickers.

- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit the Shopify Help Center or the Shopify Blog
Shopify Partner