jQuery( document ).ready(function() {
var image_to_show = '';
var full_image = '';
var variations = JSON.parse(jQuery(".variations_form").attr("data-product_variations"));
if(variations) {
var first_attr = Object.keys(variations[0].attributes)[0];
jQuery("div[data-attribute_name='attribute_pa_farben'] div").click(function() {
var choice = jQuery(this).attr("data-value");
var found = false;
for(const i in variations) {
if(found) continue;
if(variations.hasOwnProperty(i)) {
if (choice === variations[i].attributes[Object.keys(variations[0].attributes)[0]]) {
image_to_show = variations[i].image.src;
full_image = variations[i].image.full_src;
found = true;
jQuery(".woocommerce-product-gallery__wrapper a img").attr({
"src": image_to_show,
"data-o_src": image_to_show,
"data-o_data-src": full_image,
"data-src": full_image,
"data-large_image": full_image
}).removeAttr("srcset");
jQuery('.woocommerce-product-gallery__image a').attr({
"href": image_to_show,
"data-o_href": image_to_show
});
}
}
}
});
}
});