How to show gender specific images in Shopify collections?

I have looked at various threads which seemed to be relevant, but have not found a solution to what I am looking to achieve.

Our store sells unisex items, but we want to add additional feature for our customers to shop by gender too. What we would like to do is when customers selects men’s collection we want the pictures they see to have only men on it (and filter out women’s images). In all the other collections we want to see the image with only the woman instead.

We have the same system of images in all of our products:

  1. feature image is a product image (without a model), this image should be visible to all customers
    2/3. female model
    4/5/… other image visible to everyone
    As last image always the one with men model

The way we would like to achieve this is to add code to the effect of:

IF collection is “men”

THEN show images “visible to everyone” and not the image containing “woman”

IF collection is anyone else

THEN show all the images except the last one

The problem is, I am not exactly sure what code and where to write in our theme Horizontal

I’ll appreciate your help

What pops up now is we can look for the collection slug or handle for men and women. You will need to add alt text to your images of men and women. We can then check if we are on men’s collection only show images of men and so on.

I hope you don’t have too many collections and images to edit.

Yes i can do it, but what type of file i need to modify and with what code?

Since you are on horizon i can try this on my dev store first. But just to confirm can you like explain this a bit more or may be shared examples of site that have done this. I don’t know but every time I read the query i am uncertain of it.

Best