Skip to content

Instantly share code, notes, and snippets.

@ed-codes
Last active September 12, 2018 14:36
Show Gist options
  • Save ed-codes/a927c195bcfef16d39ddbb1a4283abc5 to your computer and use it in GitHub Desktop.
Save ed-codes/a927c195bcfef16d39ddbb1a4283abc5 to your computer and use it in GitHub Desktop.
Unisex products, Use the women's variant image as featured image on the womens collection page and vice versa for mens
{% for variant in product.variants %}
{% if variant.title contains "Men's"%}
{% if variant.image.src %}
{% comment %}male model shot exists. Display it.{% endcomment %}
{% assign male_image = variant.image %}
{% else %}
{% comment %}male model shot doesnt exist. Display the second image (most likely the flatlay).{% endcomment %}
{% if product.images > 1 %}
{% assign male_image = product.images[1] %}
{% else %}
{% comment %}there is only one image {% endcomment %}
{% assign male_image = product.images[0] %}
{% endif %}
{% endif %}
{% elsif variant.title contains "Women's"%}
{% if variant.image.src %}
{% comment %}female model shot exists. Display it.{% endcomment %}
{% assign female_image = variant.image %}
{% else %}
{% comment %}female model shot doesnt exist. Display the second image (most likely the flatlay).{% endcomment %}
{% if product.images > 1 %}
{% assign female_image = product.images[1] %}
{% else %}
{% comment %}there is only one image {% endcomment %}
{% assign female_image = product.images[0] %}
{% endif %}
{% endif %}
{% else %}
{% comment %}The product isnt fully set up yet{% endcomment %}
{% assign male_image = product.images[0] %}
{% assign female_image = product.images[0] %}
{% endif %}
{% endfor %}
{% if collection.title contains 'Hers' %}
<img src="{{ female_image.src | product_img_url: '500x' }}" alt="{{ female_image.alt | escape }}" data-original="{{ female_image.src | product_img_url: '500x' }}" />
{% elsif collection.title contains 'His' %}
<img src="{{ male_image.src | product_img_url: '500x' }}" alt="{{ male_image.alt | escape }}" data-original="{{ male_image.src | product_img_url: '500x' }}" />
{% else %}
{% comment %}original markup{% endcomment %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment