I want to change some functions in woocommerce account-edit page. I want user_email or account_email fields equals to billing_email.
I displayed a billing_email field in Woocommerce Edit Account Page and then try to update_user_metaa but its not working.
// add_action( 'woocommerce_edit_account_form_start', 'add_billing_email_to_edit_account_form' ); // At start
add_action( 'woocommerce_edit_account_form_start', 'add_billing_details_to_edit_account_form' );
function add_billing_details_to_edit_account_form() {
$user = wp_get_current_user();
?>
<p class="woocommerce-form-row woocommerce-form-row--first form-row form-row-first">
<label for="billing_email"><?php _e( 'Email Address', 'woocommerce' ); ?> <span class="required">*</span></label>
<input type="email" class="woocommerce-Input woocommerce-Input--email input-text" name="billing_email" id="billing_email" value="<?php echo esc_attr( $user->billing_email ); ?>" />
</p>
<?php
}
add_action( 'woocommerce_save_account_details', 'my_account_saving_billing_user', 20, 1 );
function my_account_saving_billing_user( $user_id ) {
if( isset($_POST['billing_email']) && ! empty($_POST['billing_email']) )
update_user_meta( $user_id, 'account_email', sanitize_text_field($_POST['billing_email']) );
}
I want when user update his billing_email from Woocommerce Edit Account page then user_email or account_email is also changed.
Both billing_email and user_email or account_email must be same.