Multiple ‘Add Image Gallery’ buttons due to general jQuery selector
-
Hi guys, the way way you are adding the ‘Add Image Gallery’ HTML to the product variations is problematic. It seems you are using jQuery to find any class matching
.form-row.form-row-full.options
and inserting the HTML.// Variation gallery show under variation image $(document).on('click', '.woocommerce_variation', function () { // console.log('clicked'); var galleryHTML = $(this).find('.wcgs-variation-gallery'); // console.log(galleryHTML); $(this).find('.form-row.form-row-full.options').before($(galleryHTML)); // $(this).find('.wcgs-variation-gallery').after('<p>Hello</p>'); // $('.wcgs-variation-gallery') });
You should know that other plugins may insert rows with that class
.form-row.form-row-full.options
into the variations. This means your code inserts multiple ‘Add Image Gallery’ buttons.jQuery is not the best tool for what you are trying to achieve. Instead you should look at using a hook like
woocommerce_product_after_variable_attributes
to add your HTML.
- The topic ‘Multiple ‘Add Image Gallery’ buttons due to general jQuery selector’ is closed to new replies.