Error: Option 'ajax' is not allowed for Select2 when attached to a <select> element woocommerce Error: Option 'ajax' is not allowed for Select2 when attached to a <select> element woocommerce wordpress wordpress

Error: Option 'ajax' is not allowed for Select2 when attached to a <select> element woocommerce


I had the same error in my wordpress website, and I fixed that so.

1st I want to describe where this error comes from.From WC Beta 2, they've migrated to Select2 V4. Select2 V4 is mostly compatible with Select2 V3 with a few exceptions, the main one being how AJAX search inputs work. WooCommerce has two instances of these which are affected and need some HTML markup changes to function.For Example

<input type="hidden" id="grant_access_id" name="grant_access_id" data-multiple="true" class="wc-product-search" style="width: 400px;" data-placeholder="<?php esc_attr_e( 'Search for a downloadable product…', 'woocommerce' ); ?>" data-action="woocommerce_json_search_downloadable_products_and_variations" />

was changed with

<select id="grant_access_id" class="wc-product-search" name="grant_access_id[]" multiple="multiple" style="width: 400px;" data-placeholder="<?php esc_attr_e( 'Search for a downloadable product…', 'woocommerce' ); ?>" data-action="woocommerce_json_search_downloadable_products_and_variations"></select>

In wordpress I saw that select2 takes control, and I tried to disable select2 load in my functions.php. You can see my script below

add_action( 'admin_enqueue_scripts', 'remove_views_select2' );function remove_views_select2($hook) {    if ( ( $hook == 'post.php' || $hook == 'post-new.php' ) ) {        wp_deregister_script( 'select2' );        // wp_register_script( 'views-select2-script' , 'http://your-site.com/wp-content/plugins/meta-box/js/select2/select2.min.js', array('jquery'), 3.2);    }}

So that works excellent in my case. Good luck ! 😉