Skip to content

Instantly share code, notes, and snippets.

@Fixmysite
Last active January 26, 2021 15:46
Show Gist options
  • Select an option

  • Save Fixmysite/0de66ef50e4e887ffaddfdd4656a15f8 to your computer and use it in GitHub Desktop.

Select an option

Save Fixmysite/0de66ef50e4e887ffaddfdd4656a15f8 to your computer and use it in GitHub Desktop.
/** Disable All WooCommerce Styles and Scripts Except Shop Pages*/
add_action( 'wp_enqueue_scripts', 'fixmysite_disable_woocommerce_loading_css_js' );
function fixmysite_disable_woocommerce_loading_css_js() {
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('woocommerce');
wp_dequeue_script('wc-add-to-cart');
wp_deregister_script( 'js-cookie' );
wp_dequeue_script( 'js-cookie' );
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment