Hi All,
I have been looking for a better solution to hide variant images when selecting variants on the Shopify Dawn Theme. I have seen some tutorials out there using the ALT image attribute as a place holder to identify variant images but this does not help those who actually use use alt image attributes. Having the same description over and over is not very descriptive. Also in some cases if the alt tag values are missing it messes up the variants.
I came up with the below code to hide the variant images base on image positions. Basically it works by detecting the current variant selected by the user and finding the first variant image url set inside the admin panel. (Ref: https://help.shopify.com/en/manual/products/product-media/add-images-variants). Then it finds the next variants image url and anything in between these images will be the variants images.
Note: This was tested on non-modified version of DAWN 9.0.0. YMMV depending on your theme modifications.
Firstly, setup your variant images by editing your product and add all the variant images under media. Organize the images in order by variant then set the main variant image as described in the ref link above.
Add the below code to the bottom of main-product.liquid after the last {% endschema %} tag.
IMPORTANT! Make sure to set “Desktop layout” to “Thumbnail carousel” and “Mobile layout” to “Show Thumbnails”. If these below settings are not made the code will alert the user on the front end.
Enjoy!
Disclaimer - Use this code at your own risk. I am not responsible for any loss or damages caused by altering your code and using the below code.
