Displaying percentage price on Top Left (Dawn Theme)

Solved

Displaying percentage price on Top Left (Dawn Theme)

Regency
Shopify Partner
15 0 0

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:

0b4c11cd-39f8-45d9-b0e0-0c4e3010a4f9.png

Thanks

Regency

Accepted Solutions (3)
JohnGray33
Shopify Partner
3 1 1

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 -%}

 

View solution in original post

websensepro
Shopify Partner
1220 136 156

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!

 

Need a Shopify developer?
Hire us at WebSensePro
For Shopify Design Changes | Shopify Custom Coding | Custom Modifications
Subscribe to our youtube channel or buy us a Cofee here

Free Shopify Beginner Tutorial

View solution in original post

Dan-From-Ryviu
Shopify Partner
9551 1919 1955

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.

View solution in original post

Replies 13 (13)

Dan-From-Ryviu
Shopify Partner
9551 1919 1955

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>

Screenshot 2024-09-13 at 10.49.49.pngScreenshot 2024-09-13 at 10.50.01.png

- 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.

Regency
Shopify Partner
15 0 0

Hi @Dan-From-Ryviu 

 

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/)

Untitled.png

JohnGray33
Shopify Partner
3 1 1

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 -%}

 

Regency
Shopify Partner
15 0 0

Hey @JohnGray33 

 

Can you help me fix this problem

Regency_0-1726246318460.png

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

Dan-From-Ryviu
Shopify Partner
9551 1919 1955

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.

Regency
Shopify Partner
15 0 0

Hi @Dan-From-Ryviu 

 

It worked but the sale badge is still visible

Regency_0-1726212974350.png

Also decrease the %off text size a little bit and make it bold

 

Thanks

Regency

websensepro
Shopify Partner
1220 136 156

@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>

websensepro_0-1726213272359.png

If my reply is helpful, kindly click like and mark it as an accepted solution.

Thanks!

Need a Shopify developer?
Hire us at WebSensePro
For Shopify Design Changes | Shopify Custom Coding | Custom Modifications
Subscribe to our youtube channel or buy us a Cofee here

Free Shopify Beginner Tutorial
Dan-From-Ryviu
Shopify Partner
9551 1919 1955

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.

Regency
Shopify Partner
15 0 0

Hi @Dan-From-Ryviu 

 

Can you help me with this

Regency_0-1726225110064.png

The regular price products are also having %OFF Text Help me fix it

 

Thanks

Regency

websensepro
Shopify Partner
1220 136 156

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!

 

Need a Shopify developer?
Hire us at WebSensePro
For Shopify Design Changes | Shopify Custom Coding | Custom Modifications
Subscribe to our youtube channel or buy us a Cofee here

Free Shopify Beginner Tutorial
Regency
Shopify Partner
15 0 0

Hi @websensepro 

 

Can you help me make this %OFF text bold and small in size

Thanks

Regency

Regency
Shopify Partner
15 0 0

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

Regency_0-1726223630044.png

thanks

regency

magecomp
Shopify Partner
430 29 43

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?

Helping voluntarily. Please like and accept the solution if it helps. Thanks!
Our Bestseller Shopify Apps    |      Mobile App Builder by MageComp    |      Shoplock Hide Pages/Collections

Need a developer?  Just visit MageComp website