Solved

Display a default price percentage

  • 19 March 2023
  • 4 replies
  • 215 views

Badge +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 :)

 

icon

Best answer by Tonio 20 March 2023, 14:09

View original

4 replies

Userlevel 3
Badge +9

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.

Badge +4

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

Badge +4

Hi Tonio,

 

Would you insert it here in the code?

 

Userlevel 3
Badge +9

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.

Reply