Skip to main content
Solved

How can I display the amount a person would save if they apply a coupon?


Forum|alt.badge.img+1

I want to show and calculate the amount a person would save if they apply a coupon.

I can show cart total with  {{event.extra.SubTotal}}

E.g. I want to show how much they would save if they applied a 10% discount.

However, I cannot find any information about math calculations, or whether Klaviyo even uses liquid.

 

any help is appreciated!

Best answer by Tonio

Klaviyo does support Liquid, to calculate the amount a person would save with a coupon, you can use the following Liquid code:

{% assign discount_percent = 10 %}
{% assign sub_total = event.extra.SubTotal %}
{% assign discount_amount = sub_total * discount_percent / 100 %}
{% assign total_with_discount = sub_total - discount_amount %}

You saved {{discount_amount | currency}} with your {{discount_percent}}% discount!
Your new total is {{total_with_discount | currency}}.
 

This code sets the discount percentage to 10%, retrieves the subtotal from the event.extra object, calculates the discount amount, and subtracts it from the subtotal to get the new total with the discount applied.

You can customize the discount percentage and currency formatting to suit your needs.

View original
Did this topic or the replies in the thread help you find an answer to your question?

5 replies

David To
Klaviyo Employee
Forum|alt.badge.img+60
  • Klaviyo Employee
  • 2456 replies
  • March 22, 2023

Hey @BenAdams,

Welcome to the Klaviyo Community!

Although you can perform certain math calculations in templates such as addition, multiplication, and division, subtraction is not supported. You can check our Glossary of variable filters Help Center article to see of our most commonly used ones. 

Our templates utilize Django and you can find the full scope here.

I hope this helps!

David


Forum|alt.badge.img+9
  • Expert Problem Solver I
  • 33 replies
  • Answer
  • March 23, 2023

Klaviyo does support Liquid, to calculate the amount a person would save with a coupon, you can use the following Liquid code:

{% assign discount_percent = 10 %}
{% assign sub_total = event.extra.SubTotal %}
{% assign discount_amount = sub_total * discount_percent / 100 %}
{% assign total_with_discount = sub_total - discount_amount %}

You saved {{discount_amount | currency}} with your {{discount_percent}}% discount!
Your new total is {{total_with_discount | currency}}.
 

This code sets the discount percentage to 10%, retrieves the subtotal from the event.extra object, calculates the discount amount, and subtracts it from the subtotal to get the new total with the discount applied.

You can customize the discount percentage and currency formatting to suit your needs.


Forum|alt.badge.img+1
  • Author
  • Contributor II
  • 4 replies
  • March 23, 2023

That’s great thank you.

 

I ended up doing this: ${{event.extra.SubTotal|multiply:0.1|round_up:2}}


  • Contributor I
  • 1 reply
  • April 17, 2024

Hey Tonio,

Where are you seeing the documention around including Liquid? This forum post is really the only place I’ve found. When I try to do something similar Klaviyo throws formatting errors.


Taylor Tarpley
Community Manager
Forum|alt.badge.img+60

Hi @Tonio

 

Think you can help our @johnathon here? 

 

I believe this was Tonio’s own working and not from a specific document.

 

-Taylor