ECommerce is serious business, that is why when a customer signs up to your store you want the most accurate information to stay in touch, promote your products and offer decent after sales service. Unfortunately, there are lots of chancers out there on the internet that use fraudulent cards and fake emails to purchase products from your store, which can leave you to foot the bill.
The following piece of code will prohibit usage of fake emails for creating accounts, it focuses on sharklashers.com but can easily be expanded to include other email domains by just adding to the array.
Add the following code to end of your theme’s functions.php file omitting the opening <?php tag
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Do not allow account creation with temp email addresses | |
* @param Object $validation_errors | |
* @param string $username | |
* @param string $email | |
* @return WP_Error | |
*/ | |
function do_not_allow_temp_email_addresses( $validation_errors, $username, $email ) { | |
$prohibitied_domains = array( | |
'sharklasers.com', | |
'grr.la', | |
'guerrillamail.biz', | |
'guerrillamail.com', | |
'guerrillamail.de', | |
'guerrillamail.net', | |
'guerrillamail.org', | |
'guerrillamailblock.com', | |
'spam4.me', | |
); | |
$email_domain = explode( '@', $email )[1]; | |
if ( in_array( $email_domain, $prohibitied_domains ) ) { | |
return new WP_Error( 'registration-error-bad-email', __( 'Please use a valid email address.' ) ); | |
} | |
return $validation_errors; | |
} // End do_not_allow_temp_email_addresses() | |
add_filter( 'woocommerce_registration_errors', 'do_not_allow_temp_email_addresses', 10, 3 ); |