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');
}
}
@eversionsystems
Copy link

I'm using WooCommerce 2.6.13, yes old I know but I had to use the hook wp_print_scripts to remove the scripts.

@rtpHarry
Copy link

rtpHarry commented Aug 1, 2018

Yes! @eversionsystems, thanks for the tip, this code worked for me:

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

add_action( 'wp_print_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');

    } 
} 

I had a site running WooCommerce v2.6 and ACF Pro was failing because it was getting an old version of Select2 supplied to it. Adding this snippet to my functions.php removed it before ACF tried to add its own so it is now working!

@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