Jump to content

Color print


DavidMazza

Recommended Posts

Dear,

I have this code

  // Add column "Order Notes" on the orders page
  add_filter( 'manage_edit-shop_order_columns', 'add_order_notes_column' );
  function add_order_notes_column( $columns ) {
    $new_columns = ( is_array( $columns ) ) ? $columns : array();
    $new_columns['order_notes'] = 'Order Notes';
    return $new_columns;
  }
  
  add_action( 'admin_print_styles', 'add_order_notes_column_style' );
  function add_order_notes_column_style() {
    $css = '.post-type-shop_order table.widefat.fixed { table-layout: auto; width: 100%; }';
    $css .= 'table.wp-list-table .column-order_notes { min-width: 280px; text-align: left; }';
    $css .= '.column-order_notes ul { margin: 0 0 0 18px; list-style-type: disc; }';
    $css .= '.order_customer_note { color: #ee0000; }'; // red
    $css .= '.order_private_note { color: #0000ee; }'; // blue
    wp_add_inline_style( 'woocommerce_admin_styles', $css );
  }
  
  // Add order notes to the "Order Notes" column
  add_action( 'manage_shop_order_posts_custom_column', 'add_order_notes_content' );
  function add_order_notes_content( $column ) {
    if( $column != 'order_notes' ) return;      
    global $post, $the_order;
    if( empty( $the_order ) || $the_order->get_id() != $post->ID ) {
      $the_order = wc_get_order( $post->ID );
    }    
    $args = array();
    $args['order_id'] = $the_order->get_id();
    $args['order_by'] = 'date_created';
    $args['order'] = 'ASC';
    $notes = wc_get_order_notes( $args );
    if( $notes ) {
      print '<ul>';
      foreach( $notes as $note ) {
        if( $note->customer_note ) {
          print '<li class="order_customer_note">';
        } else {
          print '<li class="order_private_note">';
        }
        $date = date( 'd/m/y H:i', strtotime( $note->date_created ) );
        print $date.' by '.$note->added_by.'<br>'.$note->content.'</li>';
      }
      print '</ul>';
    }
  } // end function

 

I would like that the color of the .order_private_note would be green if  $note->added_by =="toto"

Could you help me ?

Link to comment
Share on other sites

This is completely untested, but it makes sense...

add_action( 'admin_print_styles', 'add_order_notes_column_style' );
function add_order_notes_column_style() {
	$css = '.post-type-shop_order table.widefat.fixed { table-layout: auto; width: 100%; }';
	$css .= 'table.wp-list-table .column-order_notes { min-width: 280px; text-align: left; }';
	$css .= '.column-order_notes ul { margin: 0 0 0 18px; list-style-type: disc; }';
	$css .= '.order_customer_note { color: #ee0000; }'; // red
	$css .= '.order_private_note { color: #0000ee; }'; // blue
	$css .= ".order_private_note.toto { color: #00ee00; }"; // green
	wp_add_inline_style( 'woocommerce_admin_styles', $css );
}

// Add order notes to the "Order Notes" column
add_action( 'manage_shop_order_posts_custom_column', 'add_order_notes_content' );
function add_order_notes_content( $column ) {
	if( $column != 'order_notes' ) return;      
	global $post, $the_order;
	if( empty( $the_order ) || $the_order->get_id() != $post->ID ) {
		$the_order = wc_get_order( $post->ID );
	}    
	$args = array();
	$args['order_id'] = $the_order->get_id();
	$args['order_by'] = 'date_created';
	$args['order'] = 'ASC';
	$notes = wc_get_order_notes( $args );
	if( $notes ) {
		print '<ul>';
		foreach( $notes as $note ) {
			if( $note->customer_note ) {
				print '<li class="order_customer_note">';
			} else {
				print '<li class="order_private_note';
				if($note->added_by == 'toto'){
					print ' toto';
				}
				print '">';
			}
			$date = date( 'd/m/y H:i', strtotime( $note->date_created ) );
			print $date.' by '.$note->added_by.'<br>'.$note->content.'</li>';
		}
		print '</ul>';
	}
} // end function

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.