Thank you for updating this mod, however I do have a few improvements I'd like to pass along for inclusion in possible future versions.
First, rather than running multiple preg_match() calls, you can combine all of them into one regular expression, this provides a performance boost, as well as less duplicate code. Second, I've extended the regular expression to avoid false positives (e.g. Boxer Dr, Polk St, Box Cir, etc.).
Here is the primary snippet, which you can modify the message stack name for each instance:
PHP Code:
// BEGIN PO Box Ban 1/1
if (preg_match('/(?:^|\W)(?:(?:P\.?O\.?\s*)?BOX|P\.?O\.?)\s*\d+/i', $street_address)) {
$error = true;
$messageStack->add('addressbook', PO_BOX_ERROR);
}
// END PO Box Ban 1/1
Here is the shipping module snippet:
PHP Code:
// BEGIN PO Box Ban 1/1
if (preg_match('/(?:^|\W)(?:(?:P\.?O\.?\s*)?BOX|P\.?O\.?)\s*\d+/i', $order->delivery['street_address'])) {
$this->quotes = array(
'module' => $this->title,
'error' => '<span class="alert messageStackError">Sorry, we do not ship to PO Boxes. Please change your shipping address.</span>');
return $this->quotes;
}
// END PO Box Ban 1/1
This regular expression is case-insensitive, and will match cases such as:
- P.O. Box 123
- POBOX 123
- PO 123
- BOX 123
- BOX123
- POBOX123
- Etc.
Hopefully this will help others trying to block PO Box addresses.
Bookmarks