How can I add product variant images to color swatches?

Hey there,

I implemented a swatch variant selector in a product page with a help of an tutorial video, but in that I was able to add swatches with just a color pic that I have in the assets folder… I would like to implement now variant images to be in a place of the color pics that I currently have.


                    {%assign index = forloop.index %}  
                    

                      {% for value in option.values %}  
                        
                        
                      {% endfor %}       
                    

The close that I could get on implementing this feature was by adding “product.selected.featured_image” to the image src but with this, all the pics on the swatch are the same. (the first one selected as the parameter said). I feel this can possible be an easy fix, like finding the rich parameter to the img src but I’m not familiar with HTML and can’t really find usefull info do to it by myself. :disappointed_face:

I also have {{value}} in a code wich can possible help we came to a solution since I just need to know a way to get that {{value}} correspondent picture of the product. Any thoughts?

1 Like

@DaamnShop

Welcome to the Shopify community!
and Thanks for your Good question.

Please share your site URL,
So I will check and provide a solution here.

please flow this step

https://community.shopify.com/c/Shopify-Design/Product-pages-Add-color-swatches-to-products/td-p/616427

1 Like

Hey @KetanKumar ,

Thanks for helping me out! I saw that article too but it’s different from what I want to do sinc eit doesnt have the variant pictures on it for me to navigate throught prodcut variants… It only display the colors and thats what I have for now

https://daamnshop.tk/collections/best-sellers/products/comfy-beach-sofa
pass: Fabio

@DaamnShop

Thanks but sorry i can’t see any product swatch can you please add give me product link

1 Like

@KetanKumar Yeah sure

https://daamnshop.tk/collections/best-sellers/products/comfy-beach-sofa

You can see it above the add to cart buttom

do you have upload variant.featured_image on product admin?

i can’t see thi

1 Like

What do you mean with product admin? I changed the line of code wich takes the variant image to show up to <img src=“{{variant.featured_image | img_url: “small” }}”/> and still not working yet

Ok, I understand… Yes I uploaded every variant.featured image to the product and as you can see they work ok with the variant options

no see this step

https://help.shopify.com/en/manual/products/product-media/add-images-variants

1 Like

Yeah, already added it, If you test it on the product page youll see it’s working…

Already have the variant.featured_media for all the variants and I have also the variable {{value}} in the function which gives me the variant name. Is there anything I can do to get the variant pictures from that {{value}} data?

@DaamnShop

It can be done by doing some code customization. please send me a personal message and we can discuss what you’d like

1 Like

hey not sure if you found a solution for this, but I encountered something similar and here is a way that worked for me! Basically - you need to create a variant array and loop through it using Liquid. Here is the code that worked for me. (I would just tweak as necessary in your codebase).


Hope this helps!

Mike

1 Like

How can I use this code in Motion Theme?

You have provided a link, but it shows that the content was archived.