I am trying to dequeue the woocommerce style sheets from all pages except checkout/cart/receipt pages.
The code form the woocommerce help page (http://docs.woothemes.com/document/disable-the-default-stylesheet/) works to remove the stylesheets entirely.
add_filter( 'woocommerce_enqueue_styles', '__return_empty_array' );
I tried to use this code but it does not work:
add_action( 'wp_enqueue_scripts', 'child_manage_woocommerce_styles', 99 );
function child_manage_woocommerce_styles() {
remove_action( 'wp_head', array( $GLOBALS['woocommerce'], 'generator' ));
if ( function_exists( 'is_woocommerce' ) ) {
if ( ! is_woocommerce() && ! is_cart() && ! is_checkout() ) {
add_filter( 'woocommerce_enqueue_styles', '__return_empty_array' );
}}
}
It is because you are checking that the page is not all of it in once. You have to separate the
if
statements like:That should fix your problem.
Change && with ||
Deregister/Dequeue styles is best practice
https://codex.wordpress.org/Function_Reference/wp_deregister_style
https://codex.wordpress.org/Function_Reference/wp_dequeue_style
But you can use this filter too, to filter out woocommerce styles with any condition.