Home » WooCommerce: Add “Confirm Email Address” Field @ Checkout

WooCommerce: Add “Confirm Email Address” Field @ Checkout

by Tutor Aspire

A correct email address is worth a thousand dollars, some ecommerce expert would say 🙂 So, you don’t want your WooCommerce checkout visitors to mess up with that, do you?

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!

Let’s see how I implemented this for a freelancing client of mine – I’m sure you will be grateful!

Add an email verification field @ WooCommerce checkout

PHP Snippet: Add “Confirm Email Address” Field @ WooCommerce Checkout

/**
* @snippet       Add "Confirm Email Address" Field @ WooCommerce Checkout
* @how-to        Get tutoraspire.com FREE
* @author        Tutor Aspire
* @testedwith    WooCommerce 7
* @donate $9     https://www.tutoraspire.com
*/
 
// ---------------------------------
// 1) Make original email field half width
// 2) Add new confirm email field
 
add_filter( 'woocommerce_checkout_fields' , 'tutoraspire_add_email_verification_field_checkout' );
  
function tutoraspire_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;
}
 
// ---------------------------------
// 3) Generate error message if field values are different
 
add_action( 'woocommerce_checkout_process', 'tutoraspire_matching_email_addresses' );
 
function tutoraspire_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' );
    }
}

You may also like