Created
January 9, 2018 12:08
-
-
Save breizhwave/f57aece8534074275de150d922fceaab to your computer and use it in GitHub Desktop.
woocommerce dynamic gallery : setup image variation on get parameters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jQuery( function( $ ) { | |
var gallery_container = $('.gallery_container'); | |
var variations = {}; | |
$('.variations select').each(function(){ | |
if($(this).val() != '') { | |
variations[$(this).attr('id')] = $(this).val(); | |
}}); | |
console.log(count_length(variations)) | |
if( count_length(variations) > 0 ) { // If we have some variation data, show the associated images | |
/*setTimeout( function() { | |
gallery_container.html(''); | |
gallery_container.height(galleryHeight); | |
gallery_container.addClass('gallery_loading'); | |
}, 500);*/ | |
var data = { | |
action: "wc_dgallery_change_variation", | |
product_id: a3_dgallery_variation.product_id, | |
variations: variations, | |
security: a3_dgallery_variation.security | |
}; | |
$.get( a3_dgallery_variation.ajax_url, data, function(response) { | |
gallery_container.removeClass('gallery_loading'); | |
gallery_container.css({'height':'auto'}); | |
response = $.parseJSON( response ); | |
if ( a3_dgallery_variation.variation_gallery_effect == 'fade' ) { | |
gallery_container.fadeTo( parseInt( a3_dgallery_variation.variation_gallery_effect_speed ), 0 , function() { | |
gallery_container.html(response); | |
}).fadeTo( parseInt( a3_dgallery_variation.variation_gallery_effect_speed ), 1 ); | |
} else { | |
gallery_container.html(response); | |
} | |
}); | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function breizhwave_enqueue_sscript() | |
{ if (is_product()) | |
wp_enqueue_script( 'breizhwaveProduct', get_stylesheet_directory_uri() . '/wavejss/bw201801-product-show-get' . $min. '.js', array('jquery'), false, true ); | |
} | |
add_action( 'wp_enqueue_scripts', 'breizhwave_enqueue_sscript',2000 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://support.a3rev.com/forums/topic/preselecting-variation-set-image-not-synchronizing/