Having trouble working with SelectWoo instances of Select2 within WooCommerce

I am using Select2 within WooCommerce in some of my own custom areas and I am targeting it with some code to add and removes certain classes and it's working fine; however the SelectWoo instances used by WooCommerce themselves are not working.

Example code:

(function($) {

    $('select').each(function(e) {
        handleSelectSelections($(this));
    });


})( jQuery );

function handleSelectSelections(select) {

    var el = (select.next('.select2').length) ? jQuery(select.data('select2').$container) : select;

    if (select.val() !== "" && select.val() !== null) {
        el.addClass('has-selection');
    } else {
        el.removeClass('has-selection');
    }

}

Everything works fine, except when it gets to the actual part where it adds the class it doesn't work - no class is added.

Am I missing something here?

Answers:

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.