Checkout

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' ] == '[email protected]' ) { // 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.

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