• Hi!

    How can I fix that, when i klick on image in product gallery, it changes variable to right color.

    like here:

    Best

    ctacik

    • This topic was modified 4 months ago by James Huff. Reason: redundant link removed

    The page I need help with: [log in to see the link]

Viewing 1 replies (of 1 total)
  • Here i share code.
    If you want this functionality you need to do custom jquery.
    Check this code maybe it’s help to you

    jQuery(document).ready(function($) {
    // Map image URLs to their corresponding variation IDs
    var imageVariationMap = {};

    $('.variations_form').on('found_variation', function(event, variation) {
    if (variation && variation.image && variation.image.src) {
    imageVariationMap[variation.image.src] = variation.variation_id;
    }
    });

    // Handle image click event
    $('.woocommerce-product-gallery__image img').on('click', function() {
    var clickedImageSrc = $(this).attr('src');

    // Find the corresponding variation ID
    var variationID = imageVariationMap[clickedImageSrc];

    if (variationID) {
    // Change the selected variation
    $('input.variation_id').val(variationID).change();

    // Trigger WooCommerce variation change events
    $('.variations_form').trigger('check_variations');
    $('.variations_form').trigger('woocommerce_variation_select_change');
    $('.variations_form').trigger('woocommerce_update_variation_values');
    }
    });
    });
Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.