Skip to content

Instantly share code, notes, and snippets.

@INDIAN2020
Forked from yanknudtskov/functions.php
Created June 18, 2018 06:09
Show Gist options
  • Save INDIAN2020/c2d2fc33b91540fccb1a89abbf0a9b8f to your computer and use it in GitHub Desktop.
Save INDIAN2020/c2d2fc33b91540fccb1a89abbf0a9b8f to your computer and use it in GitHub Desktop.
How to disable all WooCommerce Scripts and Styles except for shop and product pages. NOTE: Be VERY careful with this and test properly as it may clash with other plugins #woocommerce #optimization
<?php
/*
* Disable All WooCommerce Styles and Scripts Except Shop Pages
* NOTE: Be VERY careful with this and test properly as it may clash with other plugins
*/
add_action( 'wp_enqueue_scripts', 'dequeue_woocommerce_styles_scripts', 99 );
function dequeue_woocommerce_styles_scripts() {
if ( function_exists( 'is_woocommerce' ) ) {
if ( ! is_woocommerce() && ! is_cart() && ! is_checkout() ) {
// Styles
wp_dequeue_style( 'woocommerce-general' );
wp_dequeue_style( 'woocommerce-layout' );
wp_dequeue_style( 'woocommerce-smallscreen' );
wp_dequeue_style( 'woocommerce_frontend_styles' );
wp_dequeue_style( 'woocommerce_fancybox_styles' );
wp_dequeue_style( 'woocommerce_chosen_styles' );
wp_dequeue_style( 'woocommerce_prettyPhoto_css' );
// Scripts
wp_dequeue_script( 'wc_price_slider' );
wp_dequeue_script( 'wc-single-product' );
wp_dequeue_script( 'wc-add-to-cart' );
wp_dequeue_script( 'wc-cart-fragments' );
wp_dequeue_script( 'wc-checkout' );
wp_dequeue_script( 'wc-add-to-cart-variation' );
wp_dequeue_script( 'wc-single-product' );
wp_dequeue_script( 'wc-cart' );
wp_dequeue_script( 'wc-chosen' );
wp_dequeue_script( 'woocommerce' );
wp_dequeue_script( 'prettyPhoto' );
wp_dequeue_script( 'prettyPhoto-init' );
wp_dequeue_script( 'jquery-blockui' );
wp_dequeue_script( 'jquery-placeholder' );
wp_dequeue_script( 'fancybox' );
wp_dequeue_script( 'jqueryui' );
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment