Last active
June 8, 2023 12:42
-
-
Save danielbitzer/e0448c53955f1caff0516c8cda3ffbc2 to your computer and use it in GitHub Desktop.
Copy the WooCommerce order billing address to user profile when profile email is blank
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_action( 'woocommerce_checkout_order_processed', 'my_woocommerce_copy_billing_email_to_user_profile', 10, 3 ); | |
/** | |
* Copy the order billing address to user profile when profile email is blank. | |
* | |
* Requires WooCommerce 3.0 | |
* | |
* @param $order_id | |
* @param $posted_data | |
* @param \WC_Order $order | |
*/ | |
function my_woocommerce_copy_billing_email_to_user_profile( $order_id, $posted_data, $order ){ | |
$user = $order->get_user(); | |
if ( ! $user || $user->user_email ) { | |
return; | |
} | |
$user->user_email = $order->get_billing_email(); | |
wp_update_user( $user ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment