Maged Mohamed
Maged Mohamed

Reputation: 561

Apply CSS Rule to woocommerce Product BACKEND page

We try to apply a certain css rule to a product backend page not the frontend page.

But there are 2 types of pages one which is when you click create product and one when you click edit product.

We need to apply the css rule to both of these pages.

We achieved half of the answer by determining part of url when we click add product in the backend by the solution below:

add_action( 'init', 'bbloomer_apply_css_if_url_contains_string' );

function bbloomer_apply_css_if_url_contains_string() {

$url = $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];

    if(false !== strpos( $url, 'post_type=product' )){
    echo '<style type="text/css">
         #ovaem_sectionid { display: none !important }
         </style>';
} 

}

We hope if there is a thing like (is_Product) but for the backend can be used for both when adding a new product or when editing an existing product page to apply this css.

Upvotes: 2

Views: 484

Answers (1)

7uc1f3r
7uc1f3r

Reputation: 29624

<body> contains .post-type-product class, use it as the first selector

function my_custom_css() {
    echo '<style>
        .post-type-product #ovaem_sectionid {
            display: none !important;
        } 
    </style>';
}
add_action('admin_head', 'my_custom_css' );

Upvotes: 2

Related Questions