2

So I've looked all through the documentation to see if I can find a filter hook of some sort to add an extra class name to the Wordpress/WooCommerce (CPT) post table in the backend. There must be a way somewhere, as WooCommerce adds on "status-wc-" into the html class.

Anyone able to help me out and point me in the right direction?

WooCommerce Custom Post Type

1 Answer 1

2

The function get_post_class() is used to generate these classes. You can filter post_class to change the output.

Example

is_admin() && add_filter( 'post_class', function( $classes, $class, $post_id ) {
    $post = get_post( $post_id );

    // Decide whether to add a class or not …

    $classes[] = 'my-custom-class';

    return $classes;    
}, 10, 3 );
2
  • You sir, are a legend! You don't realise how long i was looking for that through the documentation. Commented Dec 7, 2016 at 10:36
  • @JamesSimpson Never rely on external documentation, just look at the source code. I have now added a link to that code to my answer.
    – fuxia
    Commented Dec 7, 2016 at 10:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.