How to Show Percentage Discount in Sale Badge for Shopify Dawn Theme

Go To Online Store > Theme > Edit Code

>> card-product.liquid and then search badge and paste this code as show in the video

>>

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

{% comment %} {{ 'products.product.on_sale' | t }} {% endcomment %}

>>

 

Paste this code in price.liquid and scroll to the bottom where the badges code is

>>

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

{% comment %} {{ 'products.product.on_sale' | t }} {% endcomment %}