Menu Close

How To Add Confirm Email Address Field To WooCommerce Checkout

default

You may have had people register to your website site an incorrect email, and it’s quite possible that you have lost customers as a result of this. A correct email address is very valuable and you definitely don’t wont to lose customers over visitors entering an incorrect email address right?

In this tutorial, we will show you how you can add an additional input field to confirm the email address on checkout, and as an added bonus, we’ll add an error message if they don’t match like so:

How to add Confirm Email Address to WooCommerce Checkout

To achieve this, all we need to do is copy and paste the below snippet to your functions.php file:


/**
 * Add "Confirm Email Address" Field At WooCommerce Checkout
 */

add_filter( 'woocommerce_checkout_fields' , 'silva_add_email_verification_field_checkout' );
   
function silva_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;
}

/**
 * Generate error message if field values are different
 */
  
add_action('woocommerce_checkout_process', 'silva_matching_email_addresses');
  
function silva_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' );
    }
}

Once added, this will create an additional input field to confirm your email address, and will also include validation to ensure the two email addresses are correct!

Simple right?! ; )

If you’ve used this code on a recent project or need any help implementing this, simply drop us a comment below!

View Source
Posted in WooCommerce