Skip to main content
Solved

Display a default price percentage


Forum|alt.badge.img+4

Hi there,

 

i am currently using a dynamic product feed built into one of my flows which displays the default product price automatically. Is there a way to display a percentage of this price? So instead of displaying “£20” it would dynamically show “£15” automatically?

 

Would i need to insert some custom code?

 

All advice is appreciated.

 

Many thanks :)

 

Best answer by Tonio

You can use Klaviyo's Liquid scripting language to display dynamic pricing. Here is an example Liquid code that displays a price that is 25% off the original price:

{% assign original_price = product.price %}
{% assign discount = 0.25 %}
{% assign discounted_price = original_price * (1 - discount) %}

{{ discounted_price | money }}
 

This code first assigns the original price of the product to a variable called "original_price." It then assigns the discount percentage to a variable called "discount." Finally, it calculates the discounted price by multiplying the original price by (1 - discount) and assigns it to a variable called "discounted_price." The final line displays the discounted price using the "money" filter to format it as a currency.

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

4 replies

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

You can use Klaviyo's Liquid scripting language to display dynamic pricing. Here is an example Liquid code that displays a price that is 25% off the original price:

{% assign original_price = product.price %}
{% assign discount = 0.25 %}
{% assign discounted_price = original_price * (1 - discount) %}

{{ discounted_price | money }}
 

This code first assigns the original price of the product to a variable called "original_price." It then assigns the discount percentage to a variable called "discount." Finally, it calculates the discounted price by multiplying the original price by (1 - discount) and assigns it to a variable called "discounted_price." The final line displays the discounted price using the "money" filter to format it as a currency.


Forum|alt.badge.img+4
  • Author
  • Active Contributor I
  • 10 replies
  • March 21, 2023

Hi Tonio, 

 

thats exactly what i’ve been trying to achieve! Thank you for the code.

 

My one question would be, where do i insert this code? (could you provide a screenshot)

 

lastly, i can see you’ve answered many of my questions on the forums. For that i really do appreciate your advice and guidance my friend.

 

Thank you


Forum|alt.badge.img+4
  • Author
  • Active Contributor I
  • 10 replies
  • March 21, 2023

Hi Tonio,

 

Would you insert it here in the code?

 


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

Hi Tonio,

 

Would you insert it here in the code?

 

To insert the Liquid code into your existing code, you will need to replace the line that displays the original product price with the Liquid code that calculates the discounted price. Here is the updated code with the Liquid code inserted:

<td align="center" style="color: rgb(34, 36, 39); font-family: "Maison Neue", sans-serif;"> {{ item.price | times: 0.75 | money }} </td>

In this updated code, the original line that displayed the product price has been replaced with Liquid code that calculates a discounted price that is 25% off the original price. The final line in the updated code displays the discounted price using the "money" filter to format it as a currency. Note that you may need to adjust the styling and formatting of the code to ensure that it displays correctly in your flow.