To get 客户账单电子邮件,您可以使用其中之一:
- Woocommerce
WC_Order
method get_billing_email() https://docs.woocommerce.com/wc-apidocs/class-WC_Order.html#_get_billing_email
- WordPress 功能get_post_meta() https://developer.wordpress.org/reference/functions/get_post_meta/使用元键
_billing_email
来自订单 ID。
现在您可以将文本设置为2个不同地点:
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>' ;
}
代码位于活动子主题(或活动主题)的 function.php 文件中。经过测试并有效。
2) 在订单接收页面底部:
使用WC_Order
method get_billing_email() https://docs.woocommerce.com/wc-apidocs/class-WC_Order.html#_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>' ;
}
代码位于活动子主题(或活动主题)的 function.php 文件中。经过测试并有效。
或者,使用 WordPressget_post_meta() https://developer.wordpress.org/reference/functions/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
通过以下行:
$email = get_post_meta( $order_id, '_billing_email', true ); // Get Customer billing email