Add “Confirm Email Address” Field on Checkout

What about adding an “Email Verification” field? In this way, we can make sure they double check their entry – and also show an error message in case they don’t match! You can simply add following Snippet to Functions.php.

add_filter( 'woocommerce_checkout_fields' , 'codeithub_add_email_verification_field_checkout' );
   
function codeithub_add_email_verification_field_checkout( $fields ) {
  
$fields['billing']['billing_email']['class'] = array( 'form-row-first' );
  
$fields['billing']['billing_em_ver'] = array(
    'label' => 'Confirm mail Address',
    'required' => true,
    'class' => array( 'form-row-last' ),
    'clear' => true,
    'priority' => 999,
);
  
return $fields;
}
  
  
add_action('woocommerce_checkout_process', 'codeithub_matching_email_addresses');
  
function codeithub_matching_email_addresses() { 
    $email1 = $_POST['billing_email'];
    $email2 = $_POST['billing_em_ver'];
    if ( $email2 !== $email1 ) {
        wc_add_notice( 'Your email addresses do not match', 'error' );
    }
}

Before:

See also  Adding a Custom Field to Checkout page
Default Checkout Field

After:

Confirm Email Address Field

Leave a Reply

Your email address will not be published. Required fields are marked *