In checkout.php I need to block blacklisted users and deny checkout. The code below I added in PHP script works but needed fine tuning as it is having 2 issues that needed solution:
The topic is different from "Deny checkout if Street Address is on blacklist". Because, I need 2 conditions in each blacklist must be matched before denying checkout.
//Block if First name is in blacklist
$blacklistedfirstname = array("raj", "ken" ,"ber" );
foreach ($blacklistedfirstname as $blacklist_firstname) {
if (stripos($post['firstname'], $blacklist_firstname) !== false) {
$error[$type . '_firstname'] = "Oops ! Something went wrong. Contact the administrator";
}
}
// Block if address_1 in blacklist
$blacklistedaddress = array("1, Vee Street", "2,BB Street", "street2","street3");
foreach ($blacklistedaddress as $blacklist_address) {
if (stripos($post['address'], $blacklist_address) !== false) {
$error[$type . '_address_1'] = "Oops ! Something went wrong. Contact the administrator";
}
}
Two issues are: Though it works individually and block if entered values are in blacklist, I face two issues.
Issue 1. The first name condition blocks all names starting with "Raj" as it is in blacklist. for ex. if "Raju" is entered, though the name is different from what is in blacklist, it still blocks. It must block only if "Raj" is entered exactly including lower case.
Issue 2. The address_1 field has values that are in blacklisted address. But I needed to block only if Firstname and address_1 values are both in blacklist. This is because, First name can be same for many people. Also street address can be same for some people. Genuine users must not be blocked. So, this unique combination of First name and address_1 blacklist check will ensure that, the particular user alone is blocked. Also instead of throwing errors independently for these 2 fields, a common error can be added when both Firstname and address_1 field values are in blacklist.