Skip to content

Instantly share code, notes, and snippets.

@aj-adl
Last active January 6, 2016 22:49
Show Gist options
  • Save aj-adl/590b0aa2a59c927b08d5 to your computer and use it in GitHub Desktop.
Save aj-adl/590b0aa2a59c927b08d5 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