Display sale percentage instead of sale badge in Shopify theme | Dawn Customization

Display sale percentage instead of sale badge in Shopify theme | Dawn Customization

There are two cases:

1. If you want to show percentage discount on home page product card then follow the given steps

  • Go to online store in your sopify admin.
  • Click on edit code
  • Search for the card-product.liquid file.
  • Paste the given code into this file.


{%- assign difference = card_product.compare_at_price | minus: card_product.price -%}
{%- assign float_difference = difference | times: 1.0 -%}
{%- assign discount_fraction = float_difference | divided_by: card_product.compare_at_price -%}
{%- assign discount_percentage = discount_fraction | times: 100 | round -%}


{{- discount_percentage }}%

2. If you want to show percentage discount on product page then follow these steps

  • Go to online store in your shopify admin.
  • Click on edit code
  • Search for the Price.liquid file.
  • Paste the given code into this file.


{%- assign difference = product.selected_or_first_available_variant.compare_at_price | minus: product.selected_or_first_available_variant.price -%}
{%- assign float_difference = difference | times: 1.0 -%}
{%- assign discount_fraction = float_difference | divided_by: product.selected_or_first_available_variant.compare_at_price -%}
{%- assign discount_percentage = discount_fraction | times: 100 | round -%}

{{- discount_percentage }}% 

Save the changes.

 

Advance code Installation help | Hire us

Advance code Installation help | Hire us
Rs. 2,500.00
Back to blog
null