在 WooCommerce 我的账户中显示来自客户订单的账单电子邮件 编辑地址
Show billing email from customer orders in WooCommerce My account Edit address
我想在每个订单中显示客户的元“电子邮件”,但这会引发错误。
add_action( 'woocommerce_before_edit_account_address_form', 'save_billing_email_to_user', 12, 1 );
function save_billing_email_to_user( $user_id ) {
$query = new WC_Order_Query(
array(
'customer_id' => $user_id
)
);
$orders = $query->get_orders();
foreach($orders as $ro => $inn){
echo $ro['email'];
}
}
我这里哪里做错了?
改用以下重新访问的代码,该代码将查询一个订单以获取帐单电子邮件:
add_action( 'woocommerce_before_edit_account_address_form', 'save_billing_email_to_user', 12 );
function save_billing_email_to_user( $user_id ) {
$orders = wc_get_orders( array( 'customer_id' => $user_id , 'limit' => '1' ) );
if ( ! empty( $orders ) ) {
$order = reset( $orders );
$order_id = $order->get_id();
$billing_email = $order->get_billing_email();
echo $billing_email;
}
}
代码进入活动子主题(或活动主题)的 functions.php 文件。已测试并有效。
或者您可以显示客户每个订单的帐单电子邮件地址,例如:
add_action( 'woocommerce_before_edit_account_address_form', 'save_billing_email_to_user', 12 );
function save_billing_email_to_user( $user_id ) {
$orders = wc_get_orders( array( 'customer_id' => $user_id ) );
foreach( $orders as $order ){
$order_id = $order->get_id();
echo $order->get_billing_email() . '<br>';
}
}
我想在每个订单中显示客户的元“电子邮件”,但这会引发错误。
add_action( 'woocommerce_before_edit_account_address_form', 'save_billing_email_to_user', 12, 1 );
function save_billing_email_to_user( $user_id ) {
$query = new WC_Order_Query(
array(
'customer_id' => $user_id
)
);
$orders = $query->get_orders();
foreach($orders as $ro => $inn){
echo $ro['email'];
}
}
我这里哪里做错了?
改用以下重新访问的代码,该代码将查询一个订单以获取帐单电子邮件:
add_action( 'woocommerce_before_edit_account_address_form', 'save_billing_email_to_user', 12 );
function save_billing_email_to_user( $user_id ) {
$orders = wc_get_orders( array( 'customer_id' => $user_id , 'limit' => '1' ) );
if ( ! empty( $orders ) ) {
$order = reset( $orders );
$order_id = $order->get_id();
$billing_email = $order->get_billing_email();
echo $billing_email;
}
}
代码进入活动子主题(或活动主题)的 functions.php 文件。已测试并有效。
或者您可以显示客户每个订单的帐单电子邮件地址,例如:
add_action( 'woocommerce_before_edit_account_address_form', 'save_billing_email_to_user', 12 );
function save_billing_email_to_user( $user_id ) {
$orders = wc_get_orders( array( 'customer_id' => $user_id ) );
foreach( $orders as $order ){
$order_id = $order->get_id();
echo $order->get_billing_email() . '<br>';
}
}