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 this snippet?

You can place PHP snippets at the bottom of your child theme functions.php file (before "?>" if you have it). CSS, on the other hand, goes in your child theme style.css file. Make sure you know what you are doing when editing such files - if you need more guidance, please take a look at my free video tutorial "Where to Place WooCommerce Customization?"

Does this snippet (still) work?

Please let me know in the comments if everything worked as expected. I would be happy to revise the snippet if you report otherwise (please provide screenshots). I have tested this code with Storefront theme, the WooCommerce version listed above and a WordPress-friendly hosting on PHP 7+.

If you think this code saved you time & money, please join other Business Bloomer supporters and avail of 365 days of WooCommerce benefits. Thank you in advance :)

Need Help with WooCommerce Customization?

Check out these free video tutorials!

  • how-to-edit-woocommerce-with-php-snippets
  • woocommerce-hooks-add_action-list-visual
  • woocommerce-customize-single-product-page-PHP

Rodolfo Melogli

Author, WooCommerce expert and WordCamp speaker, Rodolfo has worked as a 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.

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!

  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? Support? Leave your Comment Now!
_____

If you are writing code, please wrap it between: [php]code_here[/php]. Failure to complying with this (as well as going off topic) will result in comment deletion. You should expect a reply in about a week - this is a popular blog but I need to get paid work done first. Please consider joining #BloomerArmada to ask me 1-to-1 WooCommerce questions. Thank you :)

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.