raunak-gupta
10/27/2016 - 8:15 AM

Remove WooCommerce default Assets from non WooCommerce page. To disable all mentioned scripts except cart, checkout, my-account and product

Remove WooCommerce default Assets from non WooCommerce page.

To disable all mentioned scripts except cart, checkout, my-account and product page.

// CSS files
woocommerce-layout.css
woocommerce-smallscreen.css
woocommerce.css
 
// JavaScript files
add-to-cart.min.js
jquery.blockUI.min.js
woocommerce.min.js
jquery.cookie.min.js
cart-fragments.min.js

<?php

//* Enqueue scripts and styles
add_action( 'wp_enqueue_scripts', 'crunchify_disable_woocommerce_loading_css_js' );
 
function crunchify_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'); 	
 
			## Dequeue WooCommerce scripts
			wp_dequeue_script('wc-cart-fragments');
			wp_dequeue_script('woocommerce'); 
			wp_dequeue_script('wc-add-to-cart'); 
		
		}
	}	
}