简体   繁体   English

在收到的WooCommerce订单页面上添加客户电子邮件

[英]Add customer email in a text on WooCommerce Order received page

In WooCommerce, on top of my thank you / order-received page, I've added a custom text, with the following code: 在WooCommerce中,在我的感谢/订单收到的页面之上,我添加了一个自定义文本,其中包含以下代码:

add_action( 'woocommerce_thankyou', 'my_order_received_text', 1, 0);
function my_order_received_text(){

    echo '<div class="my_thankyou2"><p>' . __('Your download link was sent to: ') . '</p></div>' ;

}

How can I get the email address of the customer added to the end of the custom text? 如何将客户的电子邮件地址添加到自定义文本的末尾?

To get the customer billing email , you can use one of those: 要获取客户帐单电子邮件 ,您可以使用以下其中一种:

Now you can set the text in 2 different locations : 现在,您可以在两个不同的位置设置文本:

1) On top of Order received page: 1)在订单收到页面之上:

add_filter( 'woocommerce_thankyou_order_received_text', 'my_order_received_text', 10, 2 );
function my_order_received_text( $text, $order ){
    if( ! is_a($order, 'WC_Order') ) {
        return $text;
    }
    // Get Customer billing email
    $email = $order->get_billing_email();

    return $text . '<br>
    <div class="my_thankyou2"><p>' . __('Your download link was sent to: ') . $email . '</p></div>' ;
}

Code goes in function.php file of your active child theme (or active theme). 代码位于活动子主题(或活动主题)的function.php文件中。 Tested and works. 经过测试和工作。


2) On bottom of Order received page: 2)在订单收到页面的底部:

Using the WC_Order method get_billing_email() this way: 以这种方式使用WC_Order方法get_billing_email()

add_action( 'woocommerce_thankyou', 'my_order_received_text', 10, 1 );
function my_order_received_text( $order_id ){
    if( ! $order_id ){
        return;
    }
    $order = wc_get_order( $order_id ); // Get an instance of the WC_Order Object
    $email = $order->get_billing_email(); // Get Customer billing email

    echo '<div class="my_thankyou2"><p>' . __('Your download link was sent to: ') . $email . '</p></div>' ;
}

Code goes in function.php file of your active child theme (or active theme). 代码位于活动子主题(或活动主题)的function.php文件中。 Tested and works. 经过测试和工作。


Alternatively, using WordPress get_post_meta() function, replacing in the function: 或者,使用WordPress get_post_meta()函数,替换函数:

$order = wc_get_order( $order_id ); // Get an instance of the WC_Order Object
$email = $order->get_billing_email(); // Get Customer billing email

By the following line: 按以下行:

$email = get_post_meta( $order_id, '_billing_email', true ); // Get Customer billing email

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在帐单地址后的 Woocommerce 订单接收页面中添加文本 - Add a text in Woocommerce order received page after the billing address 添加文本到 WooCommerce 客户完成订单 email 基于运输和订单备注 - Add a text to WooCommerce customer complete order email based on shipping and order note 按照从 woocommerce 收到的页面的顺序更改文本 - Change text in order received page from woocommerce 在 Woocommerce 中根据客户处理订单电子邮件通知有条件地添加帐户电子邮件 - Add account email conditionally on Customer processing Order email notification in Woocommerce 如何将自定义字段作为抄送添加到 WooCommerce 客户订单电子邮件 - How to add Custom Field as a CC to WooCommerce Customer Order Email 将客户email和“订单”栏中的电话添加到Woocommerce的管理订单列表中 - Add customer email and phone in "Order" column to admin orders list on Woocommerce 在Woocommerce订单接收页面中更改特定的订单详细信息文本 - Changing specific order details text in Woocommerce order received page 在 WooCommerce 客户订单详情页面中添加并保存文本字段 - Add and save a text field in WooCommerce customer order detail pages 如果使用特定的优惠券,则在WooCommerce收到的订单页面上显示自定义文本 - Display custom text on WooCommerce Order Received page if specific coupons are used WooCommerce-在“谢谢”订单接收页面上自定义“总计”文本 - WooCommerce - Customize “Total” text on Thankyou order received page
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM