Skip to content

Instantly share code, notes, and snippets.

@aj-adl
Last active August 29, 2015 14:13
Show Gist options
  • Select an option

  • Save aj-adl/f8d52515c28cfb16b007 to your computer and use it in GitHub Desktop.

Select an option

Save aj-adl/f8d52515c28cfb16b007 to your computer and use it in GitHub Desktop.
Removed WooCommerce Scripts if not needed
<?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() ) { // 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