What’s the best way to override woocommerce.css?
In my style.css I have to write those css again to override it, and put !important after each css. I think this is not the best practice to do so.
Anyone has a better idea?
Leave a Reply
You must be logged in to post a comment.
WooCommerce enqueues 3 stylesheets by default. You can disable them all using:
For details on how to disable individual WooCommerce stylesheets, see their Disable the default stylesheet article.
There’s another approach in an article by Carrie Dills. She’s using the Genesis theme but it could be reworked for other themes I think.
In essence, what she recommends is changing the order that your styles load so that your theme’s stylesheet is loaded after the WooCommerce stylesheet. i.e. it is enqueued at a higher priority.
For Genesis it looks like the below. If you can access your framework/theme’s stylesheet loading with a similar hook, you could do the same.
You can override woocommerce.css with custom.css file that can be located either in default wordpress theme or in child theme.
You can also make a fallback to default woocommerce.css if something happens to custom.css file.
Same thing is for other woocommerce frontend styles (woocommerce-layout and woocommerce-smallscreen).
If you’re doing this in child theme, then use get_stylesheet_directory_uri() instead of get_template_directory_uri() and change file path according to child theme name.
My approach is to follow the principle cascade of CSS. So basically the one that loads last will override the previous rules if no !important was defined.
Check here:
So what is the idea Load your custom CSS after the woocommerce has loaded.
Method 1: Adding a Low priority on the [add_action] for the style add_action like:
Method 2: Remove woocommerce styles, so you create your own styles
Method 3: Add dependency Array to your custom style
Hope one of the Methods helps.
You’ll find what you need in WooCommerce documentation. They offer two functions to either:
woocommerce_enqueue_styles()
function.wp_enqueue_woocommerce_style()
allowing you to override woocommerce.css.For newer versions WooCommerce 4.x+ use this: