本文介绍了将Shop Manager用户名添加到Woocommerce Admin订单说明中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在有问题.我有一个插件,可让我从管理订单列表中快速更改订单状态.不幸的是,商店经理的名字没有被传送.

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.

感谢您的帮助.

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

现在看起来像这样:

我想看看哪个用户更改了状态,如下图所示:

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

推荐答案

要将已更新订单的店铺经理的用户名添加到订单注释中,请使用以下命令:

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;
}

代码进入您的活动子主题(或活动主题)的function.php文件中.经过测试,可以正常工作.

Code goes in function.php file of your active child theme (or active theme). Tested and works..

这篇关于将Shop Manager用户名添加到Woocommerce Admin订单说明中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 17:52