I want to remove the WooCommerce block styles from the frontend. This file here:
/wp-content/plugins/woocommerce/packages/woocommerce-blocks/build/style.css?ver=4.0.0
I tried two different ways which both fail:
add_filter( 'woocommerce_enqueue_styles', '__return_empty_array', 1000 );
And this function:
function disable_scripts_styles() {
wp_dequeue_style('wc-bundle-style');
}
add_action('wp_enqueue_scripts', 'disable_scripts_styles', 1000);
Is there anything I'm doing wrong? Or do I need to use a different approach?
I just saw, that the style.css
is loaded in the footer. Could that be a problem? I could remove every other style in the head with the function above.
Edit: I found a way to remove the CSS based on the URL of the file:
wp_deregister_style('wc-block-style', get_home_url().'/wp-content/plugins/woocommerce/packages/woocommerce-blocks/build/style.css', array(), null, true);
I'm not sure if that is a valid solution. What if the file structure changes? Isn't there any other/better way?
Here is the code that will do that magic
/** Disable WooCommerce Block Styles */
function disable_woocommerce_block_styles()
{
wp_dequeue_style('wc-blocks-style');
}
add_action('wp_enqueue_scripts', 'disable_woocommerce_block_styles');
To check it you need to login out or use incognito mode. Hope this helps.