Solved

product.template.liquid embed image based on logic

electroarcade
Excursionist
17 0 19

I'm using product type and tags to show relevant shipping images on my product pages.

My concern is that filtering logic using product.type or tags does not seem to be working.

I'm seeing the image on products that don't have 'freeshipping' tag and the product.price > 225 definitely isn't triggering.

The logic seems straight forward but this product has no freeshipping tag and yet still shows an image

https://electroarcade.com.au/collections/arcade-machines/products/split-console-mix-and-match-cover-...

I added an extra {% else %} at the end just in case but no luck.


{% if product.type == 'retro arcade games console' and product.tags contains 'freeshipping' and product.price > 225 %}
<img src="https://cdn.shopify.com/s/files/1/0494/6935/8246/files/free-shipping-product-under-price.gif?v=16189..." alt="" class="free-shipping_img">
{% else if product.type == 'retro arcade games console' and product.tags contains 'freeshipping' %}
<img src="https://cdn.shopify.com/s/files/1/0494/6935/8246/files/free-shipping-over-225.gif?v=1620036880" alt="" class="free-shipping__img">
{% else %}
{% endif %}

Would appreciate your input as to where I've gone wrong here.

Thanks

Accepted Solution (1)

Jason
Shopify Expert
11190 225 2282

This is an accepted solution.

Can you first fix your else if line?

It is not:

else if

but rather

elsif

 

See reference:
https://shopify.dev/docs/themes/liquid/reference/tags/control-flow-tags

 

★ I jump on these forums in my free time to help and share some insights. Not looking to be hired, and not looking for work. http://freakdesign.com.au ★

View solution in original post

Replies 4 (4)

Jason
Shopify Expert
11190 225 2282

This is an accepted solution.

Can you first fix your else if line?

It is not:

else if

but rather

elsif

 

See reference:
https://shopify.dev/docs/themes/liquid/reference/tags/control-flow-tags

 

★ I jump on these forums in my free time to help and share some insights. Not looking to be hired, and not looking for work. http://freakdesign.com.au ★
electroarcade
Excursionist
17 0 19

Thanks Jason,

Read through that a few times but seems I somehow mixed up the else and elseif.

That's stopped it showing on some products 🙂 

The logic is still failing as showing the first image even if I move price upto 260 which should trigger the elsif here https://electroarcade.com.au/collections/arcade-machines/products/split-retro-arcade-leading-game-co...

{% if product.type == 'retro arcade games console' and product.tags contains 'freeshipping' and product.price > 260 %}
<img src="https://cdn.shopify.com/s/files/1/0494/6935/8246/files/free-shipping-product-under-price.gif?v=16189..." alt="" class="free-shipping_img">
{% elsif product.type == 'retro arcade games console' and product.tags contains 'freeshipping' %}
<img src="https://cdn.shopify.com/s/files/1/0494/6935/8246/files/free-shipping-over-225.gif?v=1620036880" alt="" class="free-shipping__img">
{% else %}
{% endif %}

electroarcade
Excursionist
17 0 19

more tweaking and sorted it all out. 

🙂

Jason
Shopify Expert
11190 225 2282

Glad you got it sorted. That elsif is an easy trap to fall into. I've done it plenty of times. You'd think i'd have it down after all these years but still the brain sometimes defaults to "else if".

★ I jump on these forums in my free time to help and share some insights. Not looking to be hired, and not looking for work. http://freakdesign.com.au ★