[英]How to add WordPress User Role to Woocommerce New Admin Order Email Subject
The Woocommerce website I am building has user roles for retail customers and wholesale customers.我正在构建的 Woocommerce 网站具有零售客户和批发客户的用户角色。 I would like to add the User Role as part of the New Order Admin Email Subject Line so that the customer service department will be able to determine which type of order it is.
我想添加用户角色作为新订单管理员电子邮件主题行的一部分,以便客户服务部门能够确定它是哪种类型的订单。 Right now the subject is "[Company Name] New customer order (22315) - August 20, 2018".
现在的主题是“[公司名称] 新客户订单 (22315) - 2018 年 8 月 20 日”。
I would like it to be "[Company Name] New customer order (22315) - August 20, 2018" where is the user role that get's pulled from WordPress.我希望它是“[公司名称] 新客户订单 (22315) - 2018 年 8 月 20 日”,从 WordPress 中提取的用户角色在哪里。
here you go :干得好 :
add_filter('woocommerce_email_subject_new_order', 'change_admin_email_subject', 1, 2);
function change_admin_email_subject($subject, $order)
{
$blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
$user_id = $order->get_user_id();
$user = get_userdata($user_id);
$user_roles = $user->roles;
if (in_array('administrator', $user_roles, true)) { //Here you can defind which role do want of course
$role = 'administrator';
} else {
$role = 'Customer';
}
$subject = sprintf('[%s] New Customer Order (%s) role %s %s', $blogname, $order->id, $role, wc_format_datetime($order->get_date_created()));
return $subject;
}
put this code in your functions.php
将此代码放在您的
functions.php
This code is test and working.这段代码是测试和工作的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.