Selecting Alternate Image In Featured Product Section

Selecting Alternate Image In Featured Product Section

greenvalleycode
Explorer
47 0 7

Hey there Shopify community!

I am trying to edit the Featured-Product section in Refresh Theme. I want it to feature the third image in the product page, not the primary image by default. I don't wish to change the main product image, because that will change the look of my store and collection pages. I only want to show the tertiary image on the Featured Product Section. 

Can anyone help?

Replies 3 (3)

NomtechSolution
Astronaut
1245 113 159
{% assign third_image = featured_product.images[2] %}
{% if third_image %}
  <img src="{{ third_image | img_url: 'master' }}" alt="{{ featured_product.title }}" />
{% else %}
  <img src="{{ featured_product.image | img_url: 'master' }}" alt="{{ featured_product.title }}" />
{% endif %}

This code checks if the product has a third image. If it does, it will display that image; otherwise, it will fall back to the primary image.

greenvalleycode
Explorer
47 0 7

Thanks... where do I add this snippet? Every time I try to add it, the page breaks 😕

greenvalleycode
Explorer
47 0 7

@NomtechSolution thanks... but where do I add this snippet? Every time I try to add it, the page breaks 😕