Copy Order Billing Address to User Profile When Profile Email is blank in WooCommerce

Copy the order billing address to user profile when profile email is blank in WooCommerce on your child site.

Snippet Type

Execute on Child Sites

Snippet

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 );
}
2 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.