Advertisement
dale3h

[WooCommerce] Order Rows CSS by Role

Nov 23rd, 2015
393
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.95 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4.  * WooCommerce Order Rows CSS by Role
  5.  *
  6.  * @author dale3h
  7.  */
  8. add_filter( 'post_class', 'wc_highlight_order_rows', 10, 3 );
  9.  
  10. function wc_highlight_order_rows( $classes, $class, $post_id ) {
  11.     $post = get_post( $post_id );
  12.  
  13.     if ( $post && in_array( $post->post_type, wc_get_order_types( 'order-meta-boxes' ) ) ) {
  14.         $user = get_userdata( $post->_customer_user );
  15.  
  16.         if ( $user->roles ) {
  17.             foreach ( $user->roles as $role ) {
  18.                 $classes[] = 'role-' . $role;
  19.             }
  20.         }
  21.     }
  22.  
  23.     return $classes;
  24. }
  25.  
  26. add_action( 'admin_head', 'wc_highlight_order_rows_stylesheet' );
  27.  
  28. function wc_highlight_order_rows_stylesheet() {
  29.     global $typenow;
  30.  
  31.     if ( in_array( $typenow, wc_get_order_types( 'order-meta-boxes' ) ) ) {
  32.         ?>
  33.         <style>
  34.             .striped > tbody > tr:nth-child(even).role-customer {
  35.                 background-color: #f5fff5;
  36.             }
  37.             .striped > tbody > tr:nth-child(odd).role-customer {
  38.                 background-color: #f0faf0;
  39.             }
  40.         </style>
  41.         <?php
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement