fbpx
Want To Add Extra Images Per Product Variation For Free? Download Now

different hook for the archive product

I want to use the shortcode to apply the variations on my product archive page because the hooks that are in the plugin do not work for me. But for the shortcode to work I have to activate the enable on archive product option on the plugin, which displays it twice. Could you tell me how to do it please ?

 

i want to use the hook woocommerce_after_shop_loop_item_title

 

this is my function for the shortcode :

function add_variation_archive() {
echo do_shortcode(‘[wvs_show_archive_variation]’);
}

add_action(‘woocommerce_after_shop_loop_item_title’, ‘add_variation_archive’);

Hakik Zaman

Hi Olivier,

Thanks for reaching out to us. Please add the following code using Code Snippets plugin:

add_action('woo_variation_swatches_pro_archive_page_loaded', function($wvs_pro){
remove_action('woocommerce_init', array( $wvs_pro, 'enable_swatches' ), 1);
add_action('woocommerce_after_shop_loop_item_title', array( $wvs_pro, 'after_shop_loop_item' ), 9);
}, 10, 1);

It will remove the default swatches from the archive page. Then you have no need to add your code, remove your code. Just use the provided code to display swatches, it will display where you have added it using the shortcode.

Note: the above code will not work inside your theme’s functions.php. So, you have to use the Code Snippets plugin. Because the theme code loads first and the snippet will run at the beginning of the site load though the swatches plugin is not loaded yet.

Thank You

Thanks, it works ! I have another problem, I am under the theme blocksy and I have an infinite loading of products but on the new products loaded I can not click on the variant image to change the main image, it does not work! What should I do?

Hakik Zaman

Hi Olivier,

We need an event from your infinite load plugin that should be triggered after new posts are loaded.

Just send this plugin to your plugin developer: https://wordpress.org/plugins/malinky-ajax-pagination/

And ask them to send triggers like the following as the Malinky Ajax Pagination plugin provides.

document.addEventListener(‘malinkyLoadPostsComplete’, function(e) {
console.log(‘LoadPostsComplete’);
});

Like this filter plugin: https://woocommerce.com/products/product-filters/

jQuery(document).ready(function( $ ){
// Your code in here
jQuery(window).on(‘wcpf_update_products’, function () {
console.log(‘Hi’);
});
});

Thank You