Shopify themes, liquid, logos, and UX
Hello. I want to display my % off only on product page not on collections on the top left above the product regular price
Here's the example:
Thanks
Regency
Solved! Go to the solution
This is an accepted solution.
Please update the code
{%- if template.name contains 'product' -%}
{%- unless product.price_varies == false and product.compare_at_price_varies %}
<div style="color: red;">
{%- assign percent = compare_at_price | minus: price | times: 100 | divided_by: compare_at_price | round -%}
{{ percent }}% off
</div>
{%- endunless -%}
{%- endif -%}
This is an accepted solution.
@Regency , try the below code:
{%- if template.name contains 'product' -%}
{%- unless product.price_varies == false and product.compare_at_price_varies %}
<div style="color: red;">
{%- assign percent = compare_at_price | minus: price | times: 100 | divided_by: compare_at_price | round -%}
{{ percent }}% off
</div>
{%- endunless -%}
{%- endif -%}
If my reply is helpful, kindly click like and mark it as an accepted solution.
Thanks!
This is an accepted solution.
Try this code.
{%- if template.name contains 'product' -%}
{%- unless product.price_varies == false and product.compare_at_price_varies %}
<div style="color: red;">
{%- assign percent = compare_at_price | minus: price | times: 100 | divided_by: compare_at_price | round -%}
<span><strong>{{ percent }}% off</strong></span>
</div>
{%- endunless -%}
{%- endif -%}
- Helpful? Like and Accept solution! or Buy me coffee
- Ryviu - Reviews & QA app: Collect product reviews, import reviews from AliExpress, Amazon, Etsy, Walmart, Shopee, Dhgate and CSV.
- Lookfy Gallery: Lookbook Image: Easy and fast to create Photo Gallery, Lookbook, Shop The Look.
- Ryviu: Aliexpress Reviews - AliExpress Reviews Importer, one-click import aliexpress reviews, export reviews to CSV file.
- Reelfy‑Shoppable Videos+Reels: Create shoppable videos to engage customers and drive more sales.
- Enjoy 1 month of Shopify for $1. Sign up now.
Hi @Regency
Go to Online Store > Themes > click '...' in the current theme > Edit code > open price.liquid file, find this line of code
{%- unless target == null and placeholder == null -%}
Paste this code below above code
<div style="color: red;">
{%- assign percent = compare_at_price | minus: price | times: 100 | divided_by: compare_at_price | round -%}
{{ percent }}% off
</div>
- Helpful? Like and Accept solution! or Buy me coffee
- Ryviu - Reviews & QA app: Collect product reviews, import reviews from AliExpress, Amazon, Etsy, Walmart, Shopee, Dhgate and CSV.
- Lookfy Gallery: Lookbook Image: Easy and fast to create Photo Gallery, Lookbook, Shop The Look.
- Ryviu: Aliexpress Reviews - AliExpress Reviews Importer, one-click import aliexpress reviews, export reviews to CSV file.
- Reelfy‑Shoppable Videos+Reels: Create shoppable videos to engage customers and drive more sales.
- Enjoy 1 month of Shopify for $1. Sign up now.
I wanted to display it only on product page not on collection and its giving an error to me its not displaying the digits Here's my store link: (https://7c868c-88.myshopify.com/)
This is an accepted solution.
Please update the code
{%- if template.name contains 'product' -%}
{%- unless product.price_varies == false and product.compare_at_price_varies %}
<div style="color: red;">
{%- assign percent = compare_at_price | minus: price | times: 100 | divided_by: compare_at_price | round -%}
{{ percent }}% off
</div>
{%- endunless -%}
{%- endif -%}
Hey @JohnGray33
Can you help me fix this problem
The %off badge is visible to all products either the product is on sale or not. Please help me display it only on products with sale
Thanks
Regency
Please update previous code to this
{%- if template.name contains 'product' -%}
{%- unless product.price_varies == false and product.compare_at_price_varies %}
<div style="color: red;">
{%- assign percent = compare_at_price | minus: price | times: 100 | divided_by: compare_at_price | round -%}
{{ percent }}% off
</div>
{%- endunless -%}
{%- endif -%}
- Helpful? Like and Accept solution! or Buy me coffee
- Ryviu - Reviews & QA app: Collect product reviews, import reviews from AliExpress, Amazon, Etsy, Walmart, Shopee, Dhgate and CSV.
- Lookfy Gallery: Lookbook Image: Easy and fast to create Photo Gallery, Lookbook, Shop The Look.
- Ryviu: Aliexpress Reviews - AliExpress Reviews Importer, one-click import aliexpress reviews, export reviews to CSV file.
- Reelfy‑Shoppable Videos+Reels: Create shoppable videos to engage customers and drive more sales.
- Enjoy 1 month of Shopify for $1. Sign up now.
It worked but the sale badge is still visible
Also decrease the %off text size a little bit and make it bold
Thanks
Regency
@Regency , try the below code:
1. Go to Online Store -> Theme -> Edit code.
2. Open your theme.liquid file
3. In theme.liquid, paste the below code before </head>
<style>
span.badge.price__badge-sale.color-scheme-4 {
display: none !important;
}
</style>
If my reply is helpful, kindly click like and mark it as an accepted solution.
Thanks!
This is an accepted solution.
Try this code.
{%- if template.name contains 'product' -%}
{%- unless product.price_varies == false and product.compare_at_price_varies %}
<div style="color: red;">
{%- assign percent = compare_at_price | minus: price | times: 100 | divided_by: compare_at_price | round -%}
<span><strong>{{ percent }}% off</strong></span>
</div>
{%- endunless -%}
{%- endif -%}
- Helpful? Like and Accept solution! or Buy me coffee
- Ryviu - Reviews & QA app: Collect product reviews, import reviews from AliExpress, Amazon, Etsy, Walmart, Shopee, Dhgate and CSV.
- Lookfy Gallery: Lookbook Image: Easy and fast to create Photo Gallery, Lookbook, Shop The Look.
- Ryviu: Aliexpress Reviews - AliExpress Reviews Importer, one-click import aliexpress reviews, export reviews to CSV file.
- Reelfy‑Shoppable Videos+Reels: Create shoppable videos to engage customers and drive more sales.
- Enjoy 1 month of Shopify for $1. Sign up now.
Can you help me with this
The regular price products are also having %OFF Text Help me fix it
Thanks
Regency
This is an accepted solution.
@Regency , try the below code:
{%- if template.name contains 'product' -%}
{%- unless product.price_varies == false and product.compare_at_price_varies %}
<div style="color: red;">
{%- assign percent = compare_at_price | minus: price | times: 100 | divided_by: compare_at_price | round -%}
{{ percent }}% off
</div>
{%- endunless -%}
{%- endif -%}
If my reply is helpful, kindly click like and mark it as an accepted solution.
Thanks!
Hi @websensepro
The code worked very well but why does it showing % Off to all products even though those products don't have any compare price
thanks
regency
Hello @Regency
You should use product label app as well to attract the customers by showing discounts on your products
try this free app https://apps.shopify.com/star-product-labels-badges?
Starting a B2B store is a big undertaking that requires careful planning and execution. W...
By JasonH Sep 23, 2024By investing 30 minutes of your time, you can unlock the potential for increased sales,...
By Jacqui Sep 11, 2024We appreciate the diverse ways you participate in and engage with the Shopify Communi...
By JasonH Sep 9, 2024