I’m using the Minimal theme. I have a code that shows only the images selected of a given variant, the other images are hidden. I’ve been using this code for over 7 years with no issues until Shopify recently changed the image url from /products/ to /files/ now the code doesn’t work on new variants. Wondering if someone can help me adjust the code to account for this. I’m getting no help from support.
The code is as follows. To the best of my knowledge (granted I put it in almost a decade ago) it was only needed on the product liquid I don’t remember putting any code anywhere else.
{% assign option_name = 'Condition' %}
{% if product.options contains option_name %}
<script>
// Grabbing product thumbnails
// Covers: Editions, Launchpad Star, Lookbook, Kickstand, Startup, Simple, Radiance, Minimal, Supply, New Standard and many more.
var thumbnails = jQuery('img[src*="/products/"]') /* All product images */
.not('#related-products img') /* Except related products, thumbnails not clickable */
.not('a[href^="/collections/"] img') /* Except related products */
.not('a[href^="/products/"] img') /* Except mini-cart products */
.not('header img') /* Except mini-cart products, thumbnails not clickable */
.not('#drawer img') /* Except mini-cart products, thumbnails not clickable, in Simple theme. */
.not(':first'); /* Except first one, i.e the main image */
var optionSelect;
{% assign option_index = 0 %}
{% for option in product.options %}
{% if option == option_name %}
{% assign option_index = forloop.index0 %}
{% endif %}
{% endfor %}
{% if product.options.size == 1 %}
optionSelect = '.single-option-selector';
{% else %}
optionSelect = 'label:contains({{ option_name }}) + .single-option-selector';
{% endif %}
jQuery('form[action="/cart/add"]').on('change', optionSelect, function() {
var optionValue = $(this).val();
thumbnails.each(function() {
var wrapper = $(this);
while ( wrapper.parent().children().length === 4 ) {
wrapper = wrapper.parent();
}
if ( jQuery(this).attr('alt') === optionValue ) {
wrapper.show();
}
else {
wrapper.hide();
}
});
});
</script>
{% endif %}
That code still works perfectly IF all the images on that product page have the /product/ url format. If all or some have the new /files/ format then ALL the variant images still show.
So I tried adding this to the code:
var thumbnails = jQuery('img[src*="/files/"]') /* All product images */
which accounts for the new “files” url. With this added the above code it functions correctly again by hiding all the other variant images BUT when you click on any variant other the first one the main image which allows you to zoom in disappears and all you’re left with just the small thumbnails. Example
So there is something else I’m not accounting for which is hiding the main image when any other variants are selected. Any ideas?

