Solved

Abandonded cart flow - how to put highest value item in email subject?

  • 16 February 2022
  • 4 replies
  • 173 views

Badge +4

Hello, 

 

I’m putting together an abandoned cart flow and for the second email I would like to put the name of the highest value item in the customers cart into the subject.

So far I’ve figured out how to pull the first item from the array using {{ event.Items.0 }}  and a random item into the subject, but would like to be able to display the highest value item. Any help with this would be greatly appreciated! 

For example, I’d like to say something like: “Don’t forget about your (Highest value item)”

Thanks :)

icon

Best answer by SMAIDesign 20 February 2022, 23:12

View original

4 replies

Userlevel 7
Badge +60

Hello @SMAIDesign,

Interesting use case for this!

You’re absolutely correct that using a variable such as {{ event.Items.0 }} would pull the first item in the event array!

One lesser known fact is that the subject line field actually accepts conditional/logic statements. Because of this capability, this would allow you to display the highest value product in your subject line through the use of a logic condition that would print the highest priced product. I’ve seen similar results through the use of a series of if/else statements within the subject line looping and evaluating products with one another. 

To learn more about creating if/else statements and conditional logic, I would suggest checking out @retention’s How To Set Show/Hide Blocks Based On A Custom Profile Property blog post as well as their wonderful comment in the following Community post:

I hope this helps!

David

Badge +4

Thanks David. 

 

So I tried creating something from those resources, but couldn’t figure out how to pull the highest value order simply. 

 

I tried putting together an if/else statement to at least pull the highest value item from the first 2 items in the cart, using this code: 

 

{% if event|lookup:'Item Count'|lt:2 %} 

{{ event.Items.0 }} selling fast - secure yours now!

{% elif {{ event.extra.line_items.0.applied_discounts.0.amount }} > {{ event.extra.line_items.1.applied_discounts.0.amount }} %}

{{ event.Items.0 }} selling fast - secure yours now!

{% else %}

{{ event.Items.1 }} selling fast - secure yours now!

{% endif %}

 

However it comes back with an error saying “could not parse the remainder: ‘{{‘ from ‘{{‘  “

 

I think the error is somewhere in here: {% elif {{ event.extra.line_items.0.applied_discounts.0.amount }} > {{ event.extra.line_items.1.applied_discounts.0.amount }} %}

 

But I’m not sure how to fix it. 

 

Any further help would be hugely aprecciated!

Userlevel 7
Badge +60

Hey @SMAIDesign,

I may suggest speaking to a developer or email designer you are familiar with for more specific assistance on creating your if/else statement. If you need help finding a developer or email designer, I would recommend speaking to some of our wonderful Klaviyo Partners who are experts on such logics. 

I’m not a developer, but taking a quick look at your if statement, there seems to be some variables and aspects that don’t seem to fit the standard django conventions Klaviyo uses that a developer can certain shed more light on. For example, lt:2 isn’t a proper variable filter.  

David

Badge +4

Okay so for anyone coming across this thread hoping to do something similar, either pulling a select item into the subject or anywhere else in the email, here is the best I’ve come up with. 

 

So I couldn’t figure out the logic to pull the highest value item from the cart in, but I’ve been able to at least compare the first 2 items and pull the highest value of those into the subject. The code I used is: 

 

{% if event.extra.line_items.0.price < event.extra.line_items.1.price %}

{{ event.Items.1 }} selling fast - secure yours now!

{% else %}

{{ event.Items.0 }} selling fast - secure yours now!

{% endif %} 

 

If you ever need help putting together anything like this for yourself check out youtube for tutorials on Python, and don’t bother with Klaviyo support as they are unhelpful. 

Reply