This guide shows you how you can introduce a new required checkout billing field which asks the user to confirm their email address. This sort of solution prevents confirmation emails not being received or even going to the wrong recipient. Specifically, this guide makes the existing billing email field half width and injects a new field next to it. If the two email fields do not match, the user cannot checkout and an error message appears letting the user know the two email addresses do not match.
/**
* Snippet Name: WooCommerce checkout confirm email address
* Snippet Author: ecommercehints.com
*/
add_filter( 'woocommerce_checkout_fields' , 'ecommercehints_confirm_email_checkout_field' );
function ecommercehints_confirm_email_checkout_field( $fields ) {
$fields['billing']['billing_email']['class'] = array( 'form-row-first' ); // Make billing email field half width
$fields['billing']['billing_confirm_email'] = array(
'label' => 'Confirm Your Email Address',
'required' => true,
'class' => array( 'form-row-last' ), // Make email confirmation field half width
'priority' => 999, // Display field at the end of the checkout form
'description' => 'We don\'t want to send the wrong person your email confirmation!',
);
return $fields;
}
add_action('woocommerce_checkout_process', 'ecommercehints_equal_emails_validation');
function ecommercehints_equal_emails_validation() {
$email_address = $_POST['billing_email'];
$confirm_email_address = $_POST['billing_confirm_email'];
if ( $email_address !== $confirm_email_address ) {
wc_add_notice( 'Your email addresses don\'t match', 'error' );
}
}
2 Responses
Hi,
Is there a way to add the confirmation email address in the woocommerce registration form?
Hey Roberto,
There sure is – check out this guide (WooCommerce Custom Text Field On Registration Form)
You’ll want to remove the function which saves the email as user meta and add a conditional if statement to make sure the two fields match (then just update the error message to whatever you please).
If you still have trouble, contact us and we’ll send you a quote for a custom snippet to meet your needs 🙂