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:
- Adds a new billing email confirmation field
- 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.
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.
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.