1jQuery(document).ready(function($) { 2 // change classes below if you modify default product cart structure 3 if ($('.product > .summary > .variations_form').length > 0) { 4 var variation_form = $('.product > .summary > .variations_form'); 5 variation_form.on( 'woocommerce_variation_has_changed', function( event, variation ){ 6 var variation = variation_form.find('input.variation_id').eq(0).val(); 7 // if variation is selected 8 if (variation) { 9 //variation changed 10 //disable default main image change by wc 11 variation_form.wc_variations_image_update(false); 12 //define ajax request for gallery full rebuild 13 var imagesHeight = $('.product').eq(0).height(); 14 $('.product').eq(0).css('height', imagesHeight); 15 var ajaxData = { 16 action: 'wvg_change_images', 17 variation: variation 18 } 19 var gallery = $('.product').find('.images').eq(0); 20 gallery.css('opacity', '0.1'); 21 $.post(wvg_ajax.ajax_url, ajaxData, function(result) { 22 if (result != 'error') { 23 variation_form.trigger('woocommerce_before_variation_has_changed'); 24 gallery.replaceWith(result); 25 gallery = $('.product').find('.images').eq(0); 26 gallery.wc_product_gallery(); 27 variation_form.trigger('woocommerce_after_variation_has_changed'); 28 } else { 29 console.log('Error changin product variation gallery'); 30 // variation_form.trigger('woocommerce_after_variation_has_changed'); 31 } 32 }); 33 $('.product').eq(0).css('height', 'auto'); 34 // if variations has been reseted 35 } else { 36 // get product ID 37 var strId = document.querySelector('.product').id; 38 var productId = parseInt(strId.replace(/[^\d.]/g, '')); 39 var ajaxDefaultData = { 40 action: 'wvg_default_gallery', 41 productId: productId 42 } 43 var gallery = $('.product').find('.images').eq(0); 44 $.post(wvg_ajax.ajax_url, ajaxDefaultData, function(result) { 45 if (result != 'error') { 46 variation_form.trigger('reset_data'); 47 gallery.replaceWith(result); 48 gallery = $('.product').find('.images').eq(0); 49 gallery.wc_product_gallery(); 50 } else { 51 console.log('Error reset product variation gallery'); 52 // variation_form.trigger('woocommerce_after_variation_has_changed'); 53 } 54 }); 55 } 56 }); 57 variation_form.on('wc_variations_image_update'); 58 } 59});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.