How to remove woocommerce script and css files

Why remove Woocommerce script and css files in WordPress?

As a great e-commerce plugin, woocommerce load too many JS and CSS files as soon as you activate it. Those JS and CSS files load in all posts and pages where you don’t need including woocommerce relative pages. Site loading speed also increases and visitors get disturbed which is not good for any e-commerce site owner.

To get over this problem, here I am going to give you the most effective WooCommerce JS and CSS file optimization tips without disturbing site performance, visitors and eCommerce functionalities.

Here is how to do?

Step 1: Open functions.php file (Assuming you are using WordPress child theme)

Step 2: Copy and paste this below codes

//* Dequeue scripts and styles
add_action( 'wp_enqueue_scripts', 'camis_disable_woocommerce_loading_css_js' );
 
function camis_disable_woocommerce_loading_css_js() { 
	// Check if WooCommerce plugin is active
	if( function_exists( 'is_woocommerce' ) ){
	 
		// Check if it's any of WooCommerce page
		if(! is_woocommerce() && ! is_cart() && ! is_checkout() ) {         
		 
		    ## Dequeue WooCommerce styles
		    wp_dequeue_style('woocommerce-layout'); 
		    wp_dequeue_style('woocommerce-general'); 
		    wp_dequeue_style('woocommerce-smallscreen');
		    wp_dequeue_style('wc-block-style');
		 
		    ## Dequeue WooCommerce scripts
		    wp_dequeue_script('wc-cart-fragments');
		    wp_dequeue_script('woocommerce'); 
		    wp_dequeue_script('wc-add-to-cart'); 
		    wp_deregister_script( 'js-cookie' );
		    wp_dequeue_script( 'js-cookie' );
		    wp_dequeue_script( 'vc_woocommerce-add-to-cart-js' );
		 
		}
	}   
}

Step 3: Save it and you are done