Skip to content

Instantly share code, notes, and snippets.

@Willem-Siebe
Last active November 19, 2018 15:55
Show Gist options
  • Save Willem-Siebe/c6d798ccba249d5bf080 to your computer and use it in GitHub Desktop.
Save Willem-Siebe/c6d798ccba249d5bf080 to your computer and use it in GitHub Desktop.
// Remove CSS and/or JS for Select2 used by WooCommerce, see https://gist.github.com/Willem-Siebe/c6d798ccba249d5bf080.
add_action( 'wp_enqueue_scripts', 'wsis_dequeue_stylesandscripts_select2', 100 );
function wsis_dequeue_stylesandscripts_select2() {
if ( class_exists( 'woocommerce' ) ) {
wp_dequeue_style( 'select2' );
wp_deregister_style( 'select2' );
wp_dequeue_script( 'select2');
wp_deregister_script('select2');
}
}
@masterbip
Copy link

masterbip commented Nov 19, 2018

Note that in more recent WooCommerce versions (I believe starting with 3.2 but couldn't find a hard confirmation), there is a forked version of select2 with a different name: selectWoo. So the code would then be:

// Remove CSS and/or JS for Select2 used by WooCommerce, see https://gist.github.com/Willem-Siebe/c6d798ccba249d5bf080.

add_action( 'wp_enqueue_scripts', 'wsis_dequeue_stylesandscripts_select2', 100 );

function wsis_dequeue_stylesandscripts_select2() {
    if ( class_exists( 'woocommerce' ) ) {
        wp_dequeue_style( 'selectWoo' );
        wp_deregister_style( 'selectWoo' );

        wp_dequeue_script( 'selectWoo');
        wp_deregister_script('selectWoo');
    } 
} 

This is the working code till today with latest woo version (19/11/2018 - Woo Ver: 3.5.1)

Sometimes "Select2" dont render in first page load, giving to the user a simple text field ... so I am going to sidable it in each of my new projects.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment