[英]How to add product SKUs to WooCommerce new order email subject
[英]How to add WordPress User Role to Woocommerce New Admin Order Email Subject
我正在构建的 Woocommerce 网站具有零售客户和批发客户的用户角色。 我想添加用户角色作为新订单管理员电子邮件主题行的一部分,以便客户服务部门能够确定它是哪种类型的订单。 现在的主题是“[公司名称] 新客户订单 (22315) - 2018 年 8 月 20 日”。
我希望它是“[公司名称] 新客户订单 (22315) - 2018 年 8 月 20 日”,从 WordPress 中提取的用户角色在哪里。
干得好 :
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;
}
将此代码放在您的functions.php
这段代码是测试和工作的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.