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

Swatches not updating in Flatsome when loaded via infinite-scroll

Hi!

Thanks for a great plugin!

However, it seems like your plugin has been broken in Flatsome for a while. The plugin works fine until new products are loaded via the infinite-scroll script.
Thankfully I managed to fix my own (pretty hacky) workaround, but I thought it would be better if you could update your plugin instead 😅.

I’ll guide you through what I’ve found:
Your plugin is listening specifically for the infinite-scroll plugin to trigger the append.infiniteScroll jQuery trigger. This part seems to work fine and the swatches should theoretically work from there. However, one of the very next things that happens within the infinite-scroll plugin is this:

// Fix Safari bug
jQuery(items).find('img').each(function (index, img) {
    img.outerHTML=img.outerHTML
})

And this unfortunately seems to break your swatches plugin 🥲

So to fix this, I’m manually listening for a script that the infinite-scroll script triggers after the swatches have been loaded, like this:

// Reset the Woo variation swatches plugin to correct Flatsome bug

$(document).on('flatsome-infiniteScroll-append', (event, response, path, items) => {

    $(items).find('.wvs-pro-loaded').each((index, item) => {

        $(item).WooVariationSwatchesPro('destroy');

    });

});

and then I’m reloading the swatches via this trigger (that comes after the “Safari bug fix”):

// Reload the swatches

$(document).on('yith_wcwl_reload_fragments', () => {

    $(document).trigger('woo_variation_swatches_pro_init');

});

This WORKS but it’s obviously not optimal. The thing is, this whole workaround would not be needed if your plugin would listen to that last trigger (yith_wcwl_reload_fragments) instead of append.infiniteScroll from the very beginning 🙂.

Is this something you could change? Thanks!

Hakik Zaman

Hi Ludivine,

Thanks for reaching out to us and for your suggestion. You triggered the YITH WishList Plugin event.

BTW, I will forward this to our development team to check.

Thank You

Hi, yes, or rather, we’re listening for the YITH WishList Plugin event and are using it to trigger a reload of the Variation Swatches plugin. 🙂

How are things looking on your end? Have you heard anything from your developers?
We’re still forced to do the entire reload thing to make the plugin work properly with the latest version(s) of Flatsome. Not the most performant hack out there if you can imagine 😅

As it stands right now, Flatsome support comes preinstalled “out of the box” with the Variation Swatches plugin, even though it doesn’t actually work properly. If that automatic check would have at least been dropped from the plugin side of things, we would have much less of a performance issue to deal with. But as I mentioned in my ticket, it would make more sense if the plugin just changed what trigger-event it listens for instead (e.g. the YITH WishList Plugin event) that way Flatsome support will work right “out of the box” again.

Thanks!

Hakik Zaman

Hi Ludivine,

Your requested event was added to our latest version.

It will be released soon. Hopefully by 2 November 2022.

Thank You