仅针对客户用户角色的已完成订单状态电子邮件通知的自定义消息 [英] Custom message on completed order status email notification only for customer user role

查看:42
本文介绍了仅针对客户用户角色的已完成订单状态电子邮件通知的自定义消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想改进 这个答案,只为客户显示已完成订单状态电子邮件的消息,而不是其他用户角色(如订阅者等).>

这是代码:

add_action( 'woocommerce_email_before_order_table', 'completed_order_mail_message', 20 );函数已完成_order_mail_message( $order ) {如果(空( $order->get_used_coupons() )&& $order->post_status == 'wc-completed' )echo '<h2 id="h2thanks">享受 20% 的折扣</h2><p id="pthanks">感谢您的购买!回来使用代码Back4More"下次购买时可获得 20% 的折扣!点击此处继续购物.</p>';}

我怎样才能实现它?

谢谢

解决方案

要在完整订单状态和仅针对客户"用户角色的电子邮件通知中启用此自定义消息,您必须获得与订单相关的用户数据,获取用户角色.然后你将在你的条件中使用它.

代码如下:

add_action( 'woocommerce_email_before_order_table', 'completed_order_mail_message', 20 );函数已完成_order_mail_message( $order ) {//获取订单用户数据以获取用户角色$user_data = get_userdata($order->customer_user);if ( empty( $order->get_used_coupons() ) && $order->post_status == 'wc-completed' && in_array('customer', $user_data->roles) )echo '<h2 id="h2thanks">享受 20% 的折扣</h2><p id="pthanks">感谢您的购买!回来使用代码Back4More"下次购买时可获得 20% 的折扣!点击此处继续购物.</p>';}

此代码位于活动子主题(或主题)的 function.php 文件或任何插件文件中.

此代码经过测试且功能齐全.

I would like to improve this code from this answer, to display a message on completed order status emails only for customers, but not for other user roles (as subscribers, etc...).

Here is that code:

add_action( 'woocommerce_email_before_order_table', 'completed_order_mail_message', 20 );
function completed_order_mail_message( $order ) {
    if ( empty( $order->get_used_coupons() ) && $order->post_status == 'wc-completed' )
        echo '<h2 id="h2thanks">Get 20% off</h2><p id="pthanks">Thank you for making this purchase! Come back and use the code "<strong>Back4More</strong>" to receive a 20% discount on your next purchase! Click here to continue shopping.</p>';
}

How can I achieve it?

Thanks

解决方案

To enable this custom message on email notification for complete order status and just for 'customer' user role, you have to get the user data related to the order, to get the user role. Then you will use it in your conditional.

Here is the code:

add_action( 'woocommerce_email_before_order_table', 'completed_order_mail_message', 20 );
function completed_order_mail_message( $order ) {

    // Getting order user data to get the user roles
    $user_data = get_userdata($order->customer_user);

    if ( empty( $order->get_used_coupons() ) && $order->post_status == 'wc-completed' && in_array('customer', $user_data->roles) )
        echo '<h2 id="h2thanks">Get 20% off</h2><p id="pthanks">Thank you for making this purchase! Come back and use the code "<strong>Back4More</strong>" to receive a 20% discount on your next purchase! Click here to continue shopping.</p>';
}

This code goes in function.php file of your active child theme (or theme) or also in any plugin file.

This code is tested and fully functional.

这篇关于仅针对客户用户角色的已完成订单状态电子邮件通知的自定义消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆