How To Remove Select2 in WooCommerce
If you ever find yourself needing to remove Select2 from WooCommerce then follow these simple steps.
Where do I put this code?
A good place for this code is inside your themes functions.php file. Plugin authors can also adapt this code for use inside their own plugins.
You’ll find the code below for disabling Select2 in WooCommerce version 3.2.1.x and below, as well as version 3.2.1 and above.
/** * Remove Select2 for WooCommerce */ function wc_disable_select2() { if ( class_exists('woocommerce') ) { wp_dequeue_style('select2'); wp_deregister_style('select2'); // WooCommerce 3.2.1.x and below wp_dequeue_script('select2'); wp_deregister_script('select2'); // WooCommerce 3.2.1+ wp_dequeue_script('selectWoo'); wp_deregister_script('selectWoo'); } } add_action('wp_enqueue_scripts', 'wc_disable_select2', 100);
How does it work?
- The first thing we do is check to see that the class woocommerce exists.
- Then, we remove the stylesheet using the wp_dequeue_style() and wp_deregister_style() functions.
- After that, we remove the supporting scripts using the wp_dequeue_script() and wp_deregister_script() functions.
- Finally, we tie it all together with an add_action call to wp_enqueue_scripts with a priority of 100 to ensure this gets executed last.
Now instead of seeing the Select2 select boxes you will see regular select boxes instead. Rejoice! Your mobile users will thank you.
Leave a Reply