WooCommerce and Divi: how to override !important CSS

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;
}
woocommerce-divi-css-important-override
WooCommerce + Divi = CSS troubles!

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!

Where to add custom code?

You should place custom PHP in functions.php and custom CSS in style.css of your child theme: where to place WooCommerce customization?

This code still works, unless you report otherwise. To exclude conflicts, temporarily switch to the Storefront theme, disable all plugins except WooCommerce, and test the snippet again: WooCommerce troubleshooting 101

Related content

Rodolfo Melogli

Business Bloomer Founder

Author, WooCommerce expert and WordCamp speaker, Rodolfo has worked as an independent WooCommerce freelancer since 2011. His goal is to help entrepreneurs and developers overcome their WooCommerce nightmares. Rodolfo loves travelling, chasing tennis & soccer balls and, of course, wood fired oven pizza. Follow @rmelogli

14 thoughts on “WooCommerce and Divi: how to override !important CSS

  1. 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?

    1. Try to still use !important and also prepend “body” or “html” to your CSS call

  2. Thank you so much! That worked for me.

    1. Nice!

  3. 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;
    }

  4. 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

    1. 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

  5. You sir should get the goddamn Nobel prize!!!! Thanks for the help Buddy!

    1. Ahah, thank you ๐Ÿ™‚

  6. 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

    1. Nat, awesome, thanks so much for your feedback!

  7. 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

    1. 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 ๐Ÿ™‚

Questions? Feedback? Customization? Leave your comment now!
_____

If you are writing code, please wrap it like so: [php]code_here[/php]. Failure to complying with this, as well as going off topic or not using the English language will result in comment disapproval. You should expect a reply in about 2 weeks - this is a popular blog but I need to get paid work done first. Please consider joining the Business Bloomer Club to get quick WooCommerce support. Thank you!

Your email address will not be published. Required fields are marked *