My Account

WooCommerce Confirm Email On Registration Form

WooCommerce registration form asking user to confirm their email address

Pre-Requisites

There are no pre-requisites in order for you to be able to implement this solution.

How To Implement This Solution?

Simply copy the pre-coded solution to your active theme’s functions.php or preferably the Code Snippets Plugin.

About This Solution

This snippet generates a new custom field on the registration form which asks the user to confirm their email address (enter it a second time). By asking the user to confirm their email address, mistakes a minimised by the user, meaning they are less likely to miss out on emails and other communications. If the confirm email address field is left empty upon registration, an error appears letting the user know it is a required field. If the new field is populated, by isn’t identical to the billing email field, an error appears letting the user know the email addresses do not match.

/**
* Snippet Name:		WooCommerce Confirm Email On Registration Form
* Snippet Author:	ecommercehints.com
*/

// Create the field and display it on the registraiton form
add_action('woocommerce_register_form', 'ecommercehints_registraion_form_confirm_email_field');
function ecommercehints_registraion_form_confirm_email_field() {
   woocommerce_form_field(
      'confirm_email',
      array(
         'type'        => 'text',
         'required'    => true,
         'label'       => 'Confirm Your Email',
         'placeholder' => 'Email Address',
		 'description' => '<small>We don\'t want to send the wrong person your email confirmation!</small>',
     ),
      (isset($_POST['confirm_email']) ? $_POST['confirm_email'] : '')
  );
}

// Show an error message if the confirm email field is empty or doesn't match the billing email field
add_action('woocommerce_register_post', 'ecommercehints_confirm_email_field_validation', 10, 3);
function ecommercehints_confirm_email_field_validation($username, $email, $errors) {
   if (empty($_POST['confirm_email'])) {
      $errors->add('confirm_email_error', 'Please confirm your email address');
   }
   if ( $email !== $_POST['confirm_email'] ) {
   $errors->add('confirm_email_error', 'Your email addresses don\'t match');
   }
}

Having This Error? "Undefined Array Key Error"

/**
* Snippet Name:		WooCommerce Confirm Email On Registration Form
* Snippet Author:	ecommercehints.com
*/

// Create the field and display it on the registraiton form
add_action('woocommerce_register_form', 'ecommercehints_registraion_form_confirm_email_field');
function ecommercehints_registraion_form_confirm_email_field() {
   woocommerce_form_field(
      'confirm_email',
      array(
         'type'        => 'text',
         'required'    => true,
         'label'       => 'Confirm Your Email',
         'placeholder' => 'Email Address',
		 'description' => '<small>We don\'t want to send the wrong person your email confirmation!</small>',
     ),
      (isset($_POST['confirm_email']) ? $_POST['confirm_email'] : '')
  );
}

// Show an error message if the confirm email field is empty or doesn't match the billing email field
add_action('woocommerce_register_post', 'ecommercehints_confirm_email_field_validation', 10, 3);
function ecommercehints_confirm_email_field_validation($username, $email, $errors) {
   if (empty($_POST['confirm_email'])) {
      $errors->add('confirm_email_error', 'Please confirm your email address');
   }
   elseif ( $email !== $_POST['confirm_email'] ) {
   $errors->add('confirm_email_error', 'Your email addresses don\'t match');
   }
}

Snippet Benefits

  • Minimise errors in data by forcing users to confirm their email address on the registration form.

100 WooCommerce Conversion Rate Optimisation Tips

This field is for validation purposes and should be left unchanged.

Let’s collaborate!

Need to outsource WordPress development?

Join forces with UnlimitedWP for an outsourced white label web development service you can truly rely on.

First Timer Here?

Sign up to receive 20% off on your first month with us.

26027
WELCOME OFFER