product.template.liquid embed image based on logic

Solved
electroarcade
Tourist
9 0 2

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

0 Likes
Jason
Shopify Expert
10354 155 1990

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 to help and share some insights. Not looking to be hired, and not looking for work.

Don't hand out staff invites or give admin password to forum members unless absolutely needed. In most cases the help you need can be handled without that.


★ http://freakdesign.com.au ★
0 Likes
electroarcade
Tourist
9 0 2

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 %}

0 Likes
electroarcade
Tourist
9 0 2

more tweaking and sorted it all out. 

0 Likes
Jason
Shopify Expert
10354 155 1990

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 to help and share some insights. Not looking to be hired, and not looking for work.

Don't hand out staff invites or give admin password to forum members unless absolutely needed. In most cases the help you need can be handled without that.


★ http://freakdesign.com.au ★
0 Likes