Opencart PO BOX Validation

If you are wanting to stop people from registering with PO Box based addresses in Opencart 1.5.x then you need to make some modifications to a few key files. The process is very straight forward and should not take long to complete.

 in catalog/controller/checkout/guest.php at about line 230 add:

//Nultz No PO BOX Address Validation

         if (preg_match("/PO Box/i",$this->request->post['address_1']) > 0) {
                $json['error']['address_1'] = $this->language->get('error_post_office_box');
            }

//Nultz No PO BOX Address Validation

 

in catalog/controller/checkout/guest_shipping.php at about line 130 add:

 

//Nultz No PO BOX Address Validation

         if (preg_match("/PO Box/i",$this->session->data['guest']['shipping']['address_1']) > 0) {
                $json['error']['address_1'] = $this->language->get('error_post_office_box');
            }

//Nultz No PO BOX Address Validation

 

in catalog/controller/checkout/register.php at about line 180 add:

//Nultz No PO BOX Address Validation

         if (preg_match("/PO Box/i",$this->request->post['address_1']) > 0) {
                $json['error']['address_1'] = $this->language->get('error_post_office_box');
            }

//Nultz No PO BOX Address Validation

 

in catalog/controller/checkout/shipping_address.php at about line 148 add:

//Nultz No PO BOX Address Validation

if (preg_match("/PO Box/i",$this->request->post['address_1']) > 0) {
                $json['error']['address_1'] = $this->language->get('error_post_office_box');
            }

//Nultz No PO BOX Address Validation

 

in catalog/controller/account/register.php at about line 399 add:

//Nultz No PO BOX Address Validation

if (preg_match("/PO Box/i",$this->request->post['address_1']) > 0) {
                $json['error']['address_1'] = $this->language->get('error_post_office_box');
            }

//Nultz No PO BOX Address Validation

 

in catalog/language/english/account/register.php under the line that says "// Error" add:

$_['error_post_office_box'] = 'Not a valid Street Address. We cannot deliver to a PO BOX!';

 

in catalog/language/english/checkout/checkout.php under the line that says "// Error" add:

$_['error_post_office_box'] = 'Not a valid Street Address. We cannot deliver to a PO BOX!';

 

Once this is done you should now have completed everything you can to prevent PO BOX addresses from being used during the checkout and account creation process.