How to unload select2 script / styles loaded with new WooCommerce 2.3.x?

we are the theme developers and we are already using the select2 ( http://select2.imtqy.com/ ) script for SELECT boxes in HTML in our wordpress theme. The new WooCommerce 2.3.x, which has just been redesigned, now also uses select2 scripts. But they redefine their styles with their own (primarily important tags) in many ways.

We cannot redefine all our CSS changes with important rules, it will be a lot of CSS mess that we don’t like. Also now our JS script loads 2 times and sometimes conflicts (because woocommerce loads its own select2 js).

My question is the best way to deactivate woocommerce select2 CSS and JS files in our theme functions? We want to use our version of the script and our stylesheet (for woocommerce selections too).

I tried using wp_dequeue_script, wp_deregister_script and the same functions available for styles, but this does not help. As I see it, woocommerce adds scripts / css AFTER our theme has already been initialized and we cannot deactivate it.

Thank.

This is the code downloaded in / includes / class -wc-frontend-scripts.php that I need to disconnect from theme functions:

self::register_script( 'select2', $assets_path . 'js/select2/select2' . $suffix . '.js', array( 'jquery' ), '3.5.2' );
self::enqueue_script( 'select2' );
wp_enqueue_style( 'select2', $assets_path . 'css/select2.css' );

How to unload these CSS / JS files into theme functions without changing the original WooCommerce files?

+4
source share
4 answers

I found a solution:

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

function mgt_dequeue_stylesandscripts() {
    if ( class_exists( 'woocommerce' ) ) {
        wp_dequeue_style( 'select2' );
        wp_deregister_style( 'select2' );

        wp_dequeue_script( 'select2');
        wp_deregister_script('select2');

    } 
} 
+21

WooCommerce (v 3.2.1), select2 script, @Dmitry . , , ..

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

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

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

   }
}
+3

, : https://gist.github.com/gregrickaby/2846416

includes/class-wc-frontend-scripts.php, , .

, , , : http://docs.woothemes.com/document/disable-the-default-stylesheet/

// Remove each style one by one
add_filter( 'woocommerce_enqueue_styles', 'jk_dequeue_styles' );
function jk_dequeue_styles( $enqueue_styles ) {
    unset( $enqueue_styles['woocommerce-general'] ); // Remove the gloss
    unset( $enqueue_styles['woocommerce-layout'] ); // Remove the layout
    unset( $enqueue_styles['woocommerce-smallscreen'] ); // Remove the smallscreen optimisation
    return $enqueue_styles;
} 
0

, . , , Woocommerce :

?wc-ajax=update_order_review

, select2 select:

<span class="select2 select2-container ... >

.

wp_dequeue_script( 'wc-checkout' ); , , , .

span css:

.woocommerce-checkout .select2-container {
    display:none;
}
0

All Articles