How to Change product image based on collection using alt text?

6 0 1

Hi, my store is selling dog and cat clothes. Both animals can wear the same product but I want the product image to show image of a dog wearing it when customers are in Dog collection, and the same when they enter Cat collection.

I tried researching about it and I think I can use that by writing an alt text, but I'm not sure which code to write to do that. Other threads don't seem to be solved as well. Can anyone point me to the right direction?

Shopify Partner
1255 263 345
{% for image in product.images %}
       {% if image.alt == 'your_alt' %}
              // do what you want
       {% else %}
                leave default
         {% endif %}
 {% endfor %}
Want to modify or custom changes on store hire me.
Email:, Skype: navrocks1
If helpful then please Like and Accept Solution.
If you are happy and want to donate Click here (Its my paypal)