简体   繁体   English

如何将 WordPress 用户角色添加到 Woocommerce 新管理员订单电子邮件主题

[英]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.

相关问题 如何将产品 SKU 添加到 WooCommerce 新订单电子邮件主题 - How to add product SKUs to WooCommerce new order email subject Woocommerce-将用户名添加到新订单电子邮件主题行 - Woocommerce - Add username to new order email subject line 在 WooCommerce 新订单 email 通知中添加运输 state - Add shipping state to subject in WooCommerce new order email notification 根据用户角色添加附件到WooCommerce新用户注册email - Add attachments based on user role to WooCommerce new user registration email WooCommerce 中新订单电子邮件通知的自定义主题 - Custom subject for New Order Email notification in WooCommerce 在Woocommerce中将订单交易ID添加到管理员新订单电子邮件通知中 - Add orders transaction id to admin new order email notification in Woocommerce 在管理新订单电子邮件模板中添加应用的优惠券代码 - WooCommerce - Add Applied Coupon Code in Admin New Order Email Template - WooCommerce 如何恢复发送到 WooCommerce 管理员的新订单的 email 中的元数据 - How to recover meta data in the email of new order sent to the WooCommerce admin WooCommerce 为 email 添加 email 订单元字段到管理员“新订单” - WooCommerce add email order meta field just for email to admin "new order" 如何让WordPress用户角色显示在新用户通知电子邮件中 - How to get WordPress user role to show in new user notification email
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM