Is there any hooks or options to display order notes in WooCommerce order page in back end ? I have tried the following code and managed to add a column.
function wc_new_order_column( $columns ) {
$columns['my_column'] = 'My column';
return $columns;
}
add_filter( 'manage_edit-shop_order_columns', 'wc_new_order_column' );
I am stuck in adding order notes
2024 Update: Handling High-Performance Order Storage (HPOS)
The following will enable back the display of Order Notes in WooCommerce 3.3+ admin orders list:
add_filter( 'manage_woocommerce_page_wc-orders_columns', 'custom_shop_order_column', 20); // HPOS
add_filter( 'manage_edit-shop_order_columns', 'custom_shop_order_column', 20);
function custom_shop_order_column( $columns )
{
$ordered_columns = array();
foreach( $columns as $key => $column ){
$ordered_columns[$key] = $column;
if( 'order_date' == $key ){
$ordered_columns['order_notes'] = __( 'Notes', 'woocommerce');
}
}
return $ordered_columns;
}
add_action('manage_woocommerce_page_wc-orders_custom_column', 'custom_shop_order_list_column_content', 10, 2); // HPOS
add_action( 'manage_shop_order_posts_custom_column' , 'custom_shop_order_list_column_content', 10, 2 );
function custom_shop_order_list_column_content( $column, $order )
{
if( ! is_a($order, 'WC_order') && $order > 0 ) {
$order = wc_get_order( $order );
}
if( ! is_a($order, 'WC_order') ) {
return;
}
if ( $column == 'order_notes' ) {
if ( $customer_note = $order->get_customer_note() ) {
echo '<span class="note-on customer tips" data-tip="' . wc_sanitize_tooltip( $customer_note ) . '">' . __( 'Yes', 'woocommerce' ) . '</span>';
}
$order_notes = (array) wc_get_order_notes( array(
'order_id' => $order->get_id(),
'limit' => 1,
'orderby' => 'date_created_gmt',
) );
$count_notes = count($order_notes);
if ( $count_notes > 0 ) {
$latest_note = current( $order_notes );
if ( isset( $latest_note->content ) && $count_notes === 1 ) {
echo '<span class="note-on tips" data-tip="' . wc_sanitize_tooltip( $latest_note->content ) . '">' . __( 'Yes', 'woocommerce' ) . '</span>';
} elseif ( isset( $latest_note->content ) ) {
// translators: %d: notes count
echo '<span class="note-on tips" data-tip="' . wc_sanitize_tooltip( $latest_note->content . '<br/><small style="display:block">' . sprintf( _n( 'Plus %d other note', 'Plus %d other notes', ( $count_notes - 1 ), 'woocommerce' ), $count_notes - 1 ) . '</small>' ) . '">' . __( 'Yes', 'woocommerce' ) . '</span>';
} else {
// translators: %d: notes count
echo '<span class="note-on tips" data-tip="' . wc_sanitize_tooltip( sprintf( _n( '%d note', '%d notes', $count_notes, 'woocommerce' ), $count_notes ) ) . '">' . __( 'Yes', 'woocommerce' ) . '</span>';
}
}
}
}
// Set Here the WooCommerce icon for your action button
add_action( 'admin_head', 'add_custom_order_status_actions_button_css' );
function add_custom_order_status_actions_button_css() {
echo '<style>
td.order_notes > .note-on { display: inline-block !important;}
span.note-on.customer { margin-right: 4px !important;}
span.note-on.customer::after { font-family: woocommerce !important; content: "\e026" !important;}
</style>';
}
Tested and works.