Make A WooCommerce Guest Confirm Their Email Address During Checkout

Many times, guests buying from a WooCommerce shop enter the wrong email, leading them to getting locked out of a newly created account and not receive order updates. A simple way to fix this is to modify the WooCommerce checkout to require guests (but not logged in customers) to confirm their email before checkout. We […]
calendar_today
Published: November 22, 2022
Founder & CEO
AI Tools For WordPress Creators
Code, learn, troubleshoot, and secure WordPress sites with the CodeWP platform and our custom AI.
Start for Free

Many times, guests buying from a WooCommerce shop enter the wrong email, leading them to getting locked out of a newly created account and not receive order updates. A simple way to fix this is to modify the WooCommerce checkout to require guests (but not logged in customers) to confirm their email before checkout.

We used CodeWP to generate two snippets that work together to ensure that guest purchasers confirm their email during the checkout process:

  1. Adds a new billing email confirmation field
  2. Makes sure the fields both match before the user can checkout

This only shows up on the checkout if the user isn't logged in (ie. is a guest).

Add The New Input

This code leverages the woocommerce_form_field function to add a new field labeled "Confirm Email" to the checkout.

[cai snippet_id="1025"]

Here's what happens when the code is installed.

Confirm That The Emails Match

This code snippet takes the value from both input fields, and confirms that both values match. Keep in mind, the "real" email address input will also confirm that the entry is actually an email, so we don't need to do that for the confirmation input.

[cai snippet_id="1022"]

If the emails don't match, we use the built in wc_add_notice function to trigger the message below.

The error notice also causes the checkout process to end, meaning no order is able to be processed until both email match.

You'll also note that ! is_user_logged_in() both are wrapped in this conditional, which means that both snippets will only run when the user isn't logged in. If we confirm all guest emails, we can safely assume that those with accounts have entered the right information, meaning that it can be disabled for customers who are already logged in.

About The Author
James LePage
Founder & CEO
More By James LePage
James LePage is an entrepreneur and founder of CodeWP, an AI platform for WordPress creators. With nearly a decade of experience founding startups and leading development agencies, James is focused on leveraging AI research and natural language processing to build smart solutions that make WordPress website creation efficient. As founder of CodeWP, James is dedicated to eliminating tedious developer searches and expensive hiring so anyone can build complex WordPress solutions easily. His technical expertise and passion for innovation drive CodeWP’s mission to serve WordPress creators globally with advanced AI capabilities.
More

More Reading

Make WordPress Easy With AI
© WPAI, Inc. 2024 | d.b.a CodeWP