Created
May 5, 2026 11:47
-
-
Save xlplugins/cb410661d3e550b3b6c85c970e569d6a to your computer and use it in GitHub Desktop.
FK Uncode Variation Gallery Bridge
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * Plugin Name: FK Uncode Variation Gallery Bridge | |
| * Description: Uncode binds its variation-gallery refresh handler inside an IIFE at $(document).ready. fkcart's update_fragments_from_session() runs replaceWith at the same point, orphaning the binding (the new node has no listener, and Single_Product isn't globally exposed). On window.load this re-fires uncode_get_variation_gallery and runs Uncode's full success chain so the lateral thumbnails rebuild. | |
| * Version: 1.0.0 | |
| */ | |
| defined( 'ABSPATH' ) || exit; | |
| add_action( 'wp_footer', function () { | |
| if ( ! function_exists( 'is_product' ) || ! is_product() ) { | |
| return; | |
| } | |
| ?> | |
| <script> | |
| jQuery(window).on('load', function () { | |
| var $ = jQuery; | |
| if ($('body').hasClass('uncode-default-product-gallery')) return; | |
| if (typeof UncodeWCParameters === 'undefined') return; | |
| $('form.variations_form').each(function () { | |
| var form = $(this); | |
| var product_div = form.closest('div.woocommerce-product-gallery--with-variation-gallery'); | |
| if (!product_div.length) return; | |
| var gallery_params = product_div.find('.woocommerce-product-gallery.images').data('gallery-options'); | |
| if (!gallery_params) return; | |
| var product_id = form.attr('data-product_id'); | |
| form.on('found_variation.fk_uncode_bridge', function (event, variation) { | |
| if (form.hasClass('is-updating-gallery')) return; | |
| form.addClass('is-updating-gallery'); | |
| var old_gallery = $('.uncode-single-product-gallery'); | |
| old_gallery.addClass('product-gallery-placeholder'); | |
| var parent_gallery = old_gallery.parent(); | |
| $.ajax({ | |
| url: UncodeWCParameters.ajax_url, | |
| type: 'post', | |
| data: { | |
| action: 'uncode_get_variation_gallery', | |
| variation: variation, | |
| product_id: product_id, | |
| clear: false, | |
| gallery_params: gallery_params, | |
| is_quick_view: false | |
| }, | |
| success: function (response) { | |
| if (!response || !response.data || !response.data.html) { | |
| form.removeClass('is-updating-gallery'); return; | |
| } | |
| var new_gallery = $(response.data.html).addClass('hidden'); | |
| (UncodeWCParameters.variation_gallery_prepend === '1' ? parent_gallery.prepend(new_gallery) : parent_gallery.append(new_gallery)); | |
| var appended = parent_gallery.find('.uncode-single-product-gallery.hidden'); | |
| appended.imagesLoaded().done(function () { | |
| var main_gallery = appended.find('.woocommerce-product-gallery'); | |
| appended.removeClass('hidden'); | |
| $('.product-gallery-placeholder').removeClass('product-gallery-placeholder'); | |
| $(window).trigger('uncode_wc_variation_gallery_loaded'); | |
| old_gallery.remove(); | |
| if (window.UNCODE_WC && UNCODE_WC.product_gallery) { UNCODE_WC.product_gallery(main_gallery); main_gallery.css('opacity', '1'); } | |
| if (window.UNCODE && UNCODE.adaptive) UNCODE.adaptive(); | |
| var lbox_enhanced = window.SiteParameters && SiteParameters.lbox_enhanced; | |
| if (window.UNCODE && UNCODE.lightbox && !lbox_enhanced) UNCODE.lightbox(); | |
| else if (window.UNCODE && UNCODE.lightgallery && lbox_enhanced) UNCODE.lightgallery(); | |
| form.removeClass('is-updating-gallery'); | |
| }); | |
| }, | |
| error: function () { form.removeClass('is-updating-gallery'); } | |
| }); | |
| }); | |
| form.trigger('check_variations'); | |
| }); | |
| }); | |
| </script> | |
| <?php | |
| }, 99 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment