Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best Way to override woocommerce.css

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?

like image 527
user3390591 Avatar asked Jul 30 '14 00:07

user3390591


People also ask

How do I change my css in Woocommerce?

Install Jetpack. Once that is done, go to your website > Dashboard > Jetpack > Settings and enable Custom CSS. Next, you can go to Appearance > Edit CSS. There you'll be able to add all your custom CSS styles.

How do I override a theme css in WordPress?

From your WordPress backend: go to: GK Theme Name –> Template options –> Advanced –> Use the override. css file [Enabled] + click the Save changes button. This enables the override. css file for use, so any changes added to the file will be applied to your site, overriding any existing rules if necessary.

How do I add a custom css file to WordPress?

Adding WordPress Custom CSS with Theme CustomizerNavigate to Appearance -> Customize section of your dashboard, scroll down to the bottom of the page and click Additional CSS. This will open an in-built tool that will allow you to add any CSS code.

Where do I find css in Woocommerce?

The woocommerce CSS files are located in the woocommerce plugin folder: woocommerce > assets > css > woocommerce. css.


1 Answers

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:

//This is the order the css load by default, at leat on the sites I have worked!!!
<link rel="stylesheet" href="http:/css/custom_styles.css" type="text/css" media="all">
<link rel="stylesheet" href="http:/css/woocomerce.css" type="text/css" media="all">

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:

function load_my_css(){
   wp_enqueue_style('custom-theme', URL TO STYLE);
}
// (the higher the number the lowest Priority)
add_action('wp_enqueue_scripts', 'load_my_css', 5000);

Method 2: Remove woocommerce styles, so you create your own styles

// Or just remove them all in one line
add_filter( 'woocommerce_enqueue_styles', '__return_false' );

Method 3: Add dependency Array to your custom style

function load_my_css(){
   wp_enqueue_style('custom-theme', URL TO STYLE, array(DEPENDECIES HERE));
}

Hope one of the Methods helps.

like image 158
T04435 Avatar answered Sep 17 '22 18:09

T04435