Skip to main content

[Woocommerce] Dynamic image for variable and single product

  • 18 June 2024
  • 2 replies
  • 39 views

Hello, 

We are using Klaviyo for our transactionnal emails and CRM. 
First some informations : 

  • Woocommerce
  • Metric used : fullfilled order but same with all
  • Single product image metric : {{ event.extra.Items.0|lookup:'$extra'|lookup:'Images'|lookup:'0'|lookup:'URL'|default:'' }}
  • Variable product metric : {{ event.extra.Items.0.Variant.Image.URL|default:'' }}
  • Table edit. Row : event.extra.Items Alias : items

{{ items|lookup:'$extra'|lookup:'Images'|lookup:'0'|lookup:'URL'|default:'' }} is showing single product image 

 

{{ items.Variant.Image.URL|default:'' }} is showing variable image product 

 

Our issue is

We are using single and variable product in our website. When we put 

 

We don’t have the dedicated image of the variation in the email but the single product image only. 

When we put 

Only the variable product image is showing in the email and when an order contain a single product there is a blank image. 

 

What we tried reading tutorials and topics : 

Replace the |default:'' in variable product image by the single product image metric but not working. 

  • {{ items.Variant.Image.URL|default:'{{ items.0|lookup:'$extra'|lookup:'Images'|lookup:'0'|lookup:'URL'|default:'' }}' }}
  • {{ items.Variant.Image.URL|default:'{{ items|lookup:'$extra'|lookup:'Images'|lookup:'0'|lookup:'URL'|default:'' }}' }}
  • {{ items.Variant.Image.URL|default:’items.0|lookup:'$extra'|lookup:'Images'|lookup:'0'|lookup:'URL'|default:''' }}
  • {{ items.Variant.Image.URL|default:’items|lookup:'$extra'|lookup:'Images'|lookup:'0'|lookup:'URL'|default:''' }}
  • {{ items.Variant.Image.URL|default:'|lookup:'$extra'|lookup:'Images'|lookup:'0'|lookup:'URL'|default:''' }}
  • {{ items.Variant.Image.URL|default:'|lookup:'$extra'|lookup:'Images'|lookup:'0'|lookup:'URL'|' }}

Add the single product at the end 

  • {{ items|lookup:'$extra'|lookup:'Images'|lookup:'0'|lookup:'URL'|default:'' }}

What we are looking for : 

 

We want the dynamic table shows the single product image when single product and when there are variations shows variations image.

 

Thank you for your help and sorry for my english. Not native.

Have a good day.

2 replies

Userlevel 5
Badge +26

@Romain Try something like this and see if it works

{% if event.extra.Items.0.Variant.Image.URL !=”” %}

{{ event.extra.Items.0.Variant.Image.URL}}

{% else %}

{{ event.extra.Items.0|lookup:'$extra'|lookup:'Images'|lookup:'0'|lookup:'URL'}}

{% endif %}

Badge

Hello, 

 

If I understand well, I put all this code in here ? 

 

I tried : 

{% if event.extra.Items.0.Variant.Image.URL !=”” %}{{ event.extra.Items.0.Variant.Image.URL}}{% else %}{{ event.extra.Items.0|lookup:'$extra'|lookup:'Images'|lookup:'0'|lookup:'URL'}}{% endif %}

{% if items.Variant.Image.URL !=”” %}{{ items.Variant.Image.URL}} {% else %} {{ items|lookup:'$extra'|lookup:'Images'|lookup:'0'|lookup:'URL'}}{% endif %}

But aren’t working got this : 

 

Thank you for your help.

 

Sincerely, 

Romain 

Reply