Reputation: 1
I am able to update status using this code In this image highlighted text is username of currently logged in user, when I changed status from dashboard it shows me name, but when I change status using code it won't show any name.
I want username should be display like in this screenshot:
Upvotes: -1
Views: 206
Reputation: 11841
add_filter('woocommerce_new_order_note_data', 'modify_added_by');
function modify_added_by($args) {
$user = get_user_by('id', get_current_user_id());
$comment_author = $user->display_name;
$comment_author_email = $user->user_email;
$args['comment_author'] = $comment_author;
$args['comment_author_email'] = $comment_author_email;
return $args;
}
Try this code
Upvotes: 1
Reputation: 254363
You can use the following hooked function to get the shop manager user name in the order note:
add_filter( 'woocommerce_new_order_note_data', 'filter_woocommerce_new_order_note_data', 10, 2 );
function filter_woocommerce_new_order_note_data( $args, $args2 ) {
if( ! $args2['is_customer_note'] && is_user_logged_in() && current_user_can( 'edit_shop_order', $args2['order_id'] ) ){
$user = get_user_by( 'id', get_current_user_id() );
$args['comment_author'] = $user->display_name;
$args['comment_author_email'] = $user->user_email;
}
return $args;
}
Code goes in function.php file of your active child theme (or active theme). Tested and works.
Related thread: Add the Shop Manager username to Woocommerce Admin Order notes
Upvotes: 0