Skip to content

Instantly share code, notes, and snippets.

@niladam
Forked from aj-adl/dequeue-woo-custom.php
Created January 6, 2016 22:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save niladam/7928a48417667721bbd4 to your computer and use it in GitHub Desktop.
Save niladam/7928a48417667721bbd4 to your computer and use it in GitHub Desktop.
<?php
// Make sure you only use opening / closing tags if needed!!!
// Late priority so WC can't jump back in and re-enqueue them
add_action( 'wp_enqueue_scripts', 'woocommerce_de_script', 100 );
// Removes WooCommerce Scripts on non shop/product/cart/checkout pages
function woocommerce_de_script() {
if ( function_exists( 'is_woocommerce' ) ) {
if ( !is_shop() && !is_cart() && !is_checkout() && !is_account_page() && !is_page_template( 'custom-template.php' ) {
// if we're not on a Woocommerce page, dequeue all of these scripts
wp_dequeue_script('wc-add-to-cart');
wp_dequeue_script('jquery-blockui');
wp_dequeue_script('jquery-placeholder');
wp_dequeue_script('woocommerce');
wp_dequeue_script('jquery-cookie');
wp_dequeue_script('wc-cart-fragments');
}
}
}
// Make sure you only use opening / closing tags if needed!!!
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment