I am a big fan of Elegant Themes, but a lot of CSS styles (mainly in Divi) contain “!important” in order to override WooCommerce styles when using the two in a combo. Now, the big problem is that we can’t override !important with another !important. Divi will win. But no matter whether Divi has been developed in a good or not so good way, there is something we can do. (NOTE: using !important is a horrible thing in CSS. Use at your own risk)
Example: the add to cart message in Divi/WooCommerce
As you can see from the screenshot, the message bar that appears in Divi once you add a single product to cart has a specific background color, which is the one you choose in Divi / theme settings.
The CSS is:
.woocommerce a.button.alt, .woocommerce-page a.button.alt, .woocommerce button.button.alt, .woocommerce-page button.button.alt, .woocommerce input.button.alt, .woocommerce-page input.button.alt, .woocommerce #respond input#submit.alt, .woocommerce-page #respond input#submit.alt, .woocommerce #content input.button.alt, .woocommerce-page #content input.button.alt, .woocommerce a.button, .woocommerce-page a.button, .woocommerce button.button, .woocommerce-page button.button, .woocommerce input.button, .woocommerce-page input.button, .woocommerce #respond input#submit, .woocommerce-page #respond input#submit, .woocommerce #content input.button, .woocommerce-page #content input.button, <strong>.woocommerce-message</strong>, .woocommerce-error, .woocommerce-info { background: #71b1d6 !important; }
Sure, it’s so simple then! Let’s override Divi !important CSS…
In your child theme stylesheet or custom CSS, you would think that the following is enough:
.woocommerce-message { background: WHITE !important; }
…but no, it doesn’t work. Unfortunately !important doesn’t “beat” !important because the parent theme will win in this case.
Let’s change core files or override !important…
The ideal, long-term solution is: Divi should change how they apply their CSS. But in the meanwhile, let’s override its !important with a little CSS trick.
// THIS WON'T WORK .woocommerce-message { background: WHITE !important; } // BUT THIS WILL WORK! .woocommerce .woocommerce-message { background: WHITE !important; }
As you can see, you can override an !important with another !important, but only if you add a more specific CSS element. In our example, we used “.woocommerce” in front of “.woocommerce-message”.
This will work!
What if there already is a value given with “!important” in the divi core css?
Im trying to declare my footer width because its going to 46% at 981px width for some reason..
I tried with “!important” but the core css already has it declared with it.
Do you have any thoughts?
Try to still use !important and also prepend “body” or “html” to your CSS call
Thank you so much! That worked for me.
Nice!
Hi Rodolfo,
Your CSS still works! Thanks! I too had white on white so I changed the background to red. Unfortunately the background for the View Cart button remained white. That button is there only if I add an item to the cart then manually open the cart.
I messed around with the CSS until this worked:
/* Make the background for the button in messages on the checkout form match background */
.woocommerce .button {
background: RED !important;
}
Cool Jerry ๐
Hello Rodolfo, thanks for the tutorial.
Unfortunately, i couldnt change the background color.
I tried with !important, without it. With the .woocommerce .woocommerce-message and without .woocommerce too. And nothing worked. And the weird thing for me is that i don’t even see an !important tag on the css. This is the CSS that i see when i inspect element:
.woocommerce .woocommerce-error, .woocommerce .woocommerce-info, .woocommerce .woocommerce-message {
background: #2ea3f2;
}
I also tried using the exact same CSS, just changing the color and adding !important and it didnt work.
Im using Divi theme. And i tried putting the CSS in the CSS box in theme settings and also putting it in the child theme CSS file.
Thanks for your help
Manuel, thanks so much for your comment! Unfortunately this looks like custom troubleshooting work and I cannot help here via the blog comments. Thanks a lot for your understanding! ~R
You sir should get the goddamn Nobel prize!!!! Thanks for the help Buddy!
Ahah, thank you ๐
Hi,
Just wanted to say I used this tutorial and fixed my issue perfectly.
When I added a single product the add to basket button was white background with white text ๐
This fixed it up a treat, so thank you!
Cheers,
Nat
Nat, awesome, thanks so much for your feedback!
Hi Rodolfo!
Firstly, thank you for this amazing post https://businessbloomer.com/woocommerce-divi-override-important-css/
After following these steps I was able to customise my template. The issue this creates is the background colour I chose is the same as the automatic font colour.
Can you please help me to change the colour of the font in the error messages?
Your help would be amazing ๐
Cheersm
Darius
Darius, thanks for your comment and kind words! If you give me your website link I’ll take a look and give you a fix (also, let me know what error message you’re talking about). Cheers ๐