Skip to content

Instantly share code, notes, and snippets.

@breizhwave
Created January 9, 2018 12:08
Show Gist options
  • Save breizhwave/f57aece8534074275de150d922fceaab to your computer and use it in GitHub Desktop.
Save breizhwave/f57aece8534074275de150d922fceaab to your computer and use it in GitHub Desktop.
woocommerce dynamic gallery : setup image variation on get parameters
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);
}
});
}
});
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 );
@breizhwave
Copy link
Author

breizhwave commented Jan 9, 2018

Little bug fix / new feature for very good woocommerce plugin https://a3rev.com/shop/woocommerce-dynamic-gallery/
when pre selecting attributes via GET arguments on product page,
the associated variation image was not shown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment