0

I'm trying to add select2 to an input in WooCommerce variable product admin.

I've added select2 to a class so it can be reused, however, it seems it's not working. It's working anywhere else on the page, but not in the variations meta box.

My initial theory was that the variations load when clicked from the product data container, so I found this event woocommerce_variations_loaded and binded a function here that then applied the select2 - but it didn't work.

So, I'm back to square one. What am I doing wrong, and how can I get this to work?

(function($) {
    "use strict";

    $('.select2').select2();

    $('#woocommerce-product-data').on('woocommerce_variations_loaded', function(event) {
        $('.select2').select2();
    });

})( jQuery );

Any ideas? TIA.

0

Can you try this?

(function($) {
    "use strict";

    $('.select2').select2();

    $(document).on('woocommerce_variations_loaded', function(event) {
        $(document).find('.select2').select2();
    });

})( jQuery );

Not tested. Thanks

1
  • Doesn't seem related to event delegation, unfortunately. This doesn't work. :( – Jake Feb 12 '20 at 11:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.