Need Help Displaying Savings in card-product.liquid File

Need Help Displaying Savings in card-product.liquid File

solutionaand
Visitor
1 0 0

 

 

Hi everyone,

I'm trying to modify my `card-product.liquid` file to display the amount of money saved on each product instead of the default "Sale" label. I followed the instructions and code provided by an AI, and also consulted the guide in this [Shopify Community post](https://community.shopify.com/c/shopify-design/how-to-make-a-quot-sale-quot-label-show-quot-save-x-q...), but it's not working as expected.

Here's the line of code I added to my script:

```liquid
{%- assign savings = card_product.compare_at_price | minus: card_product.price -%}
Save ${{ savings }}
```

I also tried the revised code to calculate and show the percentage savings:

```liquid
{%- assign savings = card_product.compare_at_price | minus: card_product.price -%}
{%- if card_product.compare_at_price > 0 -%}
{%- assign savings_percentage = savings | times: 100 | divided_by: card_product.compare_at_price -%}
Save {{ savings_percentage | round: 2 }}%
{%- endif -%}
```

Despite adding the `compare_at_price` and `price` for each variant in bulk edit, the amount of money saved doesn't display live on my product cards.

Can someone please help me figure out what I'm doing wrong? Any advice on how to correctly implement this feature would be greatly appreciated!

Thank you!

 

Replies 0 (0)