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

  • WooCommerce: Add CSS to Order Emails
    Unlike your WordPress theme, you can’t just add CSS to your style.css in order to customize the look of the WooCommerce emails. This handy PHP snippet is therefore the only viable solution. It’s a little tricky but once you get the idea, adding CSS to Order Emails is a breeze.
  • WooCommerce: Change the “Remove this Item” Icon @ Cart
    I have a very long to-write list. Possibly I have enough content for another 2 years 🙂 However, the other day a premium WooCommerce student asked me for some feedback on his custom CSS – so I had to give it priority! The request was: what’s the easiest way to change the little icon/button on […]
  • WordPress: How to Add CSS to a Specific URL
    This is an interesting topic. A WordPress/WooCommerce client could not add CSS via the usual way. In fact, Gravity Forms plugin (and in particular the “directory” extension), stores entries in the database BUT the directory page and the entries filtered list have the same classes, ids, and cannot be “targeted” with CSS. Long story short, […]
  • WooCommerce: Product Category as Body Class @ Single Product Page
    A Business Bloomer fan asked me an interesting question this week: how to apply CSS on the single product page based on the product category? Well, the answer is pretty simple: if we’re able to add the category name to the HTML “body”, this can then be targeted in your custom CSS. So, let’s see […]
  • WooCommerce: Full Width Featured Image @ Single Product Page
    The standard layout for the WooCommerce single product page features the main/featured product image on the left and the title/add to cart on the right. But what if you need to turn that image into a hero one i.e. a full width featured image, and push the title and add to cart button under it? […]

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!

  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 *