WooCommerce Prevent Specific Email Address From Checking Out

WooCommerce checkout error because of 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 checks the billing email field upon the user clicking the place order button and if this email matches the email you have defined in this code, a custom error will appear, the cart is emptied, and the user will not be able to check out. In this example, we have let the user know their email is suspicious, their cart has been emptied, and to leave the website. This snippet is useful if you are finding the same email address is spamming your store with fake orders or maybe even a competitor trying to snoop around your store. If you’re finding you’re checkout is being spammed by bots, trying different cards for example, you should probably start with DNS. Start by rate limiting, country, and IP blocking.

				
					/**
 * Snippet Name:	WooCommerce Prevent Email From Checking Out 
 * Snippet Author:	ecommercehints.com
 */

add_action( 'woocommerce_after_checkout_validation', 'ecommercehints_validate_checkout_email_address', 10, 2);
function ecommercehints_validate_checkout_email_address($fields, $errors) {
	if ( $fields[ 'billing_email' ] == 'spammer@spam-mail.com' ) { // The email address to block
		$errors->add( 'validation', 'Your email address has been flagged as suspicious and your cart has been emptied. Please leave this website.' );
    }
	WC()->cart->empty_cart(); // Empty the cart
}
				
			

Snippet Benefits

  • Prevent user by spamming your checkout by validating their email address.
WooCommerce Conversion Rate Optimisation (CRO) eBook
100 WooCommerce Conversion Rate Optimisation Tips

Leave a Reply

If you are going to write code in the comments, please wrap it between code tags.

Your email address will not be published. Required fields are marked *

Other Recent Guides

Subscribe To Emails

Get exclusive WooCommerce tips that I only share with email subscribers

Join hundreds of other subscribers