Disable WooCommerce JS & CSS on Pages Note Commerce-Related?
-
Hello,
Is it possible to use you plugin to disable the loading of all Woocommerce script on pages that have no commerce element and have it load only on the pages that are commerce related, such as shop, product, checkout, and cart pages? In the provided link you can clearly see our site is not commerce based. In fact, none of the commerce pages are readily available.
Here is an example of script I’ve found on the Internet that is supposed to do the above. What I want to know is: can I use your plugin to implement this script instead or writing it directly to the them?
If is is possible, could you please explain the process were I a WordPress beginner, please?
Thank you!
Here is the code in question:
//* Enqueue scripts and styles
add_action( ‘wp_enqueue_scripts’, ‘crunchify_disable_woocommerce_loading_css_js’ );function crunchify_disable_woocommerce_loading_css_js() {
// Check if WooCommerce plugin is active
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(‘wc-cart-fragments’);
wp_dequeue_script(‘woocommerce’);
wp_dequeue_script(‘wc-add-to-cart’);wp_deregister_script( ‘js-cookie’ );
wp_dequeue_script( ‘js-cookie’ );}
}
}The page I need help with: [log in to see the link]
The topic ‘Disable WooCommerce JS & CSS on Pages Note Commerce-Related?’ is closed to new replies.