Add the Shop Manager username to Woocommerce Admin Order notes

爷,独闯天下 提交于 2019-12-01 10:56:44

问题


I have a problem right now. I have a plugin that allows me to quickly change the status of my orders from the admin order list. Unfortunately the name of the shop manager is not transmitted.

I think I've found the right code, but I don't know exactly how to do it.

Would be grateful for any help.

public function save_comment($order, $status_comment) {
    $order->add_order_note("[[" . wc_get_order_status_name($order->post_status) . "|" . $status_comment . "]]");
}

Right now it looks like this :

I'd like to see which user changed the status as shown in this picture:


回答1:


To add the username of the shop manager that has updated the Order to the order note, use the following:

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..



来源:https://stackoverflow.com/questions/54734573/add-the-shop-manager-username-to-woocommerce-admin-order-notes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!