![](/img/trans.png)
[英]Set WordPress user email instead of billing email as default value for WooCommerce checkout field
[英]Updating WordPress account email with WooCommerce billing email after checkout
我需要更新 WordPress 帳戶 email 與 woocommerce 計費 Z0C83F57C786A0B4A39EFAB2373 成功后結帳EBCZ1。 我使用了這段代碼,但它不起作用:
/* Update account email based on woocommerce billing email */
add_filter( 'woocommerce_thankyou' , 'custom_update_checkout_fields', 10, 2 );
function custom_update_checkout_fields($user_id, $old_user_data ) {
$current_user = wp_get_current_user();
// Updating Billing info
if($current_user->user_email != $current_user->billing_email)
update_user_meta($user_id, 'billing_email', $current_user->user_email);
}
我是否使用過時的代碼?
有一些錯誤。 請嘗試以下操作:
add_filter( 'woocommerce_thankyou' , 'thankyou_update_wordpress_user_email' );
function thankyou_update_wordpress_user_email( $order_id ) {
$order = wc_get_order( $order_id );
$user = $order->get_user();
$billing_email = $order->get_billing_email();
// Updating user account email
if( is_a($user, 'WP_User' ) && $user->user_email != $billing_email ) {
$user_data = wp_update_user( array( 'ID' => $user->ID, 'user_email' => $billing_email ) );
}
}
代碼進入活動子主題(或活動主題)的functions.php文件。 它應該工作。
注意:當更改用戶 email、WordPress 時,將 email 發送給新用戶 Z0C83F57C37310B4A39EFABC
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.