Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // WooCommerce - Add order notes column to orders list
- // Code goes in functions.php for your child theme
- // not tested in a PHP snippet plugin
- // 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
Advertisement
Comments
-
- Hi - how would this code look if I only want to display author private comments and not the ones the system includes (i.e. "changed status to....")? Great code!
-
- lines 39 - 46 become:
- foreach( $notes as $note ) {
- if( $note->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>';
- }
- }
-
- Hi Lorro I tried this change (39-46) and it didn't alter anything?
- If possible would only like to see customer or staff manual notes (not system notes)
- Thanks!
-
- Works for me, sorry I can't debug it on another site via comment/post communication.
- To exclude customer notes and private notes generated by 'system', lines 39 - 46 become:
- foreach( $notes as $note ) {
- if( ! $note->customer_note ) {
- if( $note->added_by != 'system' ) {
- 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>';
- }
- }
- }
-
- Is there a way to only show one system generated note that has been filtered by keyword or phrase.
- Example only show:
- 13/12/20 15:41 by system
- "Answer to the Secret Question": qkgjfkq2i4
-
- The PHP function strpos() can do that.
- if( strpos( $note->content, 'Answer to the Secret Question' ) === 0 ) {
- The === means the test string must be at the beginning of the content to give TRUE.
-
Comment was deleted
-
- Thanks! Can you show me add this to the code?
-
- Sorry, I have other commitments at the moment.
Add Comment
Please, Sign In to add comment
Advertisement