How to Remove Select2 And SelectWoo From Woocommerce

We ran into an interesting bug the other day on an ecommerce site with Woocommerce. We didn’t have time to fully debug this and needed a quick fix because this was a high-traffic website that needed a fix asap. This took us a long time to debug but luckily had a few customers who were willing to walk us through their trouble.

The customers had complained that they were getting to the checkout and having problems getting past the checkout part where it asks for your billing/shipping information. They would fill it in and then the next step where you choose your shipping options wouldn’t load.

In testing with the customers, we found that the issue was that their browser was auto-filling the shipping information but not really… If they let it autofill, they would have to manually enter the country and state (and only those 2 fields). So, even though the interface showed the correct information for these 2 fields, they still had to manually set them.

Luckily, these 2 fields shared the same functionality – they are both select boxes that are manipulated by the DOM by Select2.  Select2 and SelectWoo are built-in to Woocommerce and make select boxes a bit nicer and add a search field so the user can start typing to filter down their choice.

Select2 and SelectWoo work by hiding the real select box and adding in a new one with fancy styling. Unfortunately, for whatever reason, it doesn’t seem like autofill functionalities work with this anymore.

So, we decided to just remove Select2 from Woocommerce. This will also remove SelectWoo from Woocommerce:

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

        wp_dequeue_script( 'selectWoo');
        wp_deregister_script('selectWoo');
    } 
}
add_action( 'wp_enqueue_scripts', 'dequeue_select2_selectwoo', 100 );

Leave a Reply

Your email address will not be published. Required fields are marked *