Block Disposable Email Addresses at Checkout
Refuses orders placed with throwaway email services, so order confirmations, downloads and receipts reach a real inbox.
Opens WPIDE on
Code
$wpide_disposable_domains = array( 'mailinator.com', 'guerrillamail.com', '10minutemail.com', 'tempmail.com', 'yopmail.com', 'trashmail.com', 'sharklasers.com', 'getnada.com', 'temp-mail.org', 'dispostable.com' );
add_action( 'woocommerce_after_checkout_validation', function ( $data, $errors ) use ( $wpide_disposable_domains ) {
$email = strtolower( (string) ( $data['billing_email'] ?? '' ) );
if ( false === strpos( $email, '@' ) ) {
return;
}
$domain = substr( strrchr( $email, '@' ), 1 );
foreach ( $wpide_disposable_domains as $blocked ) {
if ( $domain === $blocked || substr( $domain, -strlen( '.' . $blocked ) ) === '.' . $blocked ) {
$errors->add( 'validation', 'Please use a permanent email address so we can send your order details.' );
return;
}
}
}, 10, 2 );
Notes
Add domains to the list as you spot them; subdomains of listed domains are blocked too.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.