Variant selector

Variant selector

Kiel2
Visitor
2 0 0

Hello Guys,

 

Trying to work this block
The variant selector should be matched with the product images but doesn't work. 
can anyone help?

 

variant selector.jpg

 

Replies 2 (2)

JasmeetVT14313
Shopify Partner
292 63 77

Hi @Kiel2 
Can you please share the store URL and the task in detail so that I can help you better.

- VTN Customer Dashboard enhances your customer's dashboard with advanced features, profile management, and order tracking. Free trial available.
- Feel free to contact me at jasmeet.kaur@vtnetzwelt.com

Small_Task_Help
Shopify Partner
915 32 85

Hi,

 

Hope variants and images are correctly linked ? if it is ok then you need to add javascript for variant image switching

 

Javascript code example

document.addEventListener("DOMContentLoaded", function() {
    var productSelect = document.querySelector('.product-form select[name=id]');
    var productImages = document.querySelectorAll('.product-single__photo');
    
    productSelect.addEventListener('change', function() {
        var selectedVariant = this.value;

        productImages.forEach(function(img) {
            if (img.dataset.variantId == selectedVariant) {
                img.style.display = 'block';
            } else {
                img.style.display = 'none';
            }
        });
    });
});

 

Add data attributes to product images (to link them to variant IDs)

{% for image in product.images %}
    <img class="product-single__photo" data-variant-id="{{ image.variant_id }}" src="{{ image.src | img_url: 'large' }}" alt="{{ image.alt }}">
{% endfor %}

 

Hope this will help. If you are not able to implement the above code then you can go for Shopify developer 

To Get Shopify Experts Help, Click Here or E-mail - hi@ecommercesmalltask.com
About Us - We are Shopify Expert India
At Google My Business - Ecommerce Small Task - Hire Shopify Developers Ahmedabad