Hi Marián,
Thanks for reaching out to us. Please use the following instead of your previous code:
window.WP_Grid_Builder && WP_Grid_Builder.on( 'init', function( wpgb ) {
wpgb.grid.on( 'loaded', function( args ) {
jQuery(document).trigger('woo_variation_swatches_pro_init');
});
});
Then let me know whether it helps or not. Hope to hear from you soon.
Thank You
Issue with “Variation Swatches For WooCommerce” Plugin Not Working with AJAX
Marián Vojtko
Dear Variation Swatches For WooCommerce Support Team,
I hope this email finds you well. I am using your plugin on my website and have recently encountered an issue with the plugin not loading correctly during AJAX page load.
My website uses the WP Grid Builder plugin along with a repeater in Oxygen to display products. The setup is hooked to AJAX pagination through WP Grid Builder. I attempted to implement a code provided by the developer to properly load the variation swatches after the AJAX page load, but I’m still encountering issues.
Here is the code I’ve been working with:
window.WP_Grid_Builder && WP_Grid_Builder.on( 'init', function( wpgb ) {
wpgb.grid.on( 'loaded', function( args ) {
$('.variations_form').each(function(){
$(this).wc_variation_form();
});
});
});
I’ve inserted this code into the repeater element JavaScript code block using the Code Snippets plugin. However, the swatches do not appear to be displaying correctly after the AJAX load.
Following some back-and-forth communication with WP Grid Builder support, they have provided me with an alternative code. But it also doesn’t seem to be working as expected. Here is their recommended code:
window.addEventListener( 'wpgb.loaded', onLoad );
function onLoad() {
WP_Grid_Builder.on( 'init', onInit );
}
function onInit( wpgb ) {
wpgb.facets.on( 'appended', onAppended );
}
function onAppended() {
if ( ! window.wc_add_to_cart_variation_params ) {
return;
}
jQuery( '.variations_form' ).each( function() {
jQuery( this ).wc_variation_form();
} );
}
Upon discussing the issue with WP Grid Builder support further, they suggested that I reach out to your team for assistance as they noted that no elements with the class name
variations_form
exist on my website, which is why nothing happens when the AJAX page loads.My website can be found at https://grandesport.tempurl.host/. I would greatly appreciate your help in resolving this issue. Please feel free to let me know if there are any further details or access required to assist in diagnosing and addressing the issue.
P.S.: Variation swatches is implemented with shortcode [wvs_show_archive_variation] in archive page repeater.
Thank you for your time and assistance.
Best regards,
Marian Vojtko