Zen Cart How to Disable P O Box Addresses for the UPS Shipping Module

If your zen cart uses the UPS shipping module but you do not want your customers to be able to enter a PO Box address, you will have to add some custom code to your zen cart UPS shipping module. This Easy Help Zen Cart Tutorial will show you how to add custom php code to your UPS module so that your customers can not enter PO Box addresses.

In your favorite plain text editor open the includes/modules/shipping/ups.php file. Be sure to back up this file in case you make a mistake and need to restore the back up to your zen cart in a hurry.

Find this:


      // disable only when entire cart is free shipping
      if (zen_get_shipping_enabled($this->code)) {
        $this->enabled = ((MODULE_SHIPPING_UPS_STATUS == 'True') ? true : false);
      }

Immediately after, add this:


// bof: block PO BOX addresses in $order->delivery['street_address'] or $order->delivery['suburb']
if (!IS_ADMIN_FLAG) {
global $order;
$street_address = $order->delivery['street_address'];
// BEGIN PO Box Ban street address
    if ( preg_match('/PO BOX/si', $street_address) ) {
      $error = true;
    } else if ( preg_match('/BOX/si', $street_address) ) {
      $error = true;
    } else if ( preg_match('/POBOX/si', $street_address) ) {
      $error = true;
    } else if ( preg_match('/P\.O\./si', $street_address) ) {
      $error = true;
    } else if ( preg_match('/P\.O/si', $street_address) ) {
      $error = true;
    } else if ( preg_match('/PO\./si', $street_address) ) {
      $error = true;
    }

$suburb = $order->delivery['suburb'];
// BEGIN PO Box Ban suburb
    if ( preg_match('/PO BOX/si', $suburb) ) {
      $error = true;
    } else if ( preg_match('/BOX/si', $suburb) ) {
      $error = true;
    } else if ( preg_match('/POBOX/si', $suburb) ) {
      $error = true;
    } else if ( preg_match('/P\.O\./si', $suburb) ) {
      $error = true;
    } else if ( preg_match('/P\.O/si', $suburb) ) {
      $error = true;
    } else if ( preg_match('/PO\./si', $suburb) ) {
      $error = true;
    }

    if ($error) {
      $this->enabled = false;
    }
}
// eof: block PO BOX addresses in $order->delivery['street_address'] or $order->delivery['suburb']

So you should have this:


      // disable only when entire cart is free shipping
      if (zen_get_shipping_enabled($this->code)) {
        $this->enabled = ((MODULE_SHIPPING_UPS_STATUS == 'True') ? true : false);
      }

// bof: block PO BOX addresses in $order->delivery['street_address'] or $order->delivery['suburb']
if (!IS_ADMIN_FLAG) {
global $order;
$street_address = $order->delivery['street_address'];
// BEGIN PO Box Ban street address
    if ( preg_match('/PO BOX/si', $street_address) ) {
      $error = true;
    } else if ( preg_match('/BOX/si', $street_address) ) {
      $error = true;
    } else if ( preg_match('/POBOX/si', $street_address) ) {
      $error = true;
    } else if ( preg_match('/P\.O\./si', $street_address) ) {
      $error = true;
    } else if ( preg_match('/P\.O/si', $street_address) ) {
      $error = true;
    } else if ( preg_match('/PO\./si', $street_address) ) {
      $error = true;
    }

$suburb = $order->delivery['suburb'];
// BEGIN PO Box Ban suburb
    if ( preg_match('/PO BOX/si', $suburb) ) {
      $error = true;
    } else if ( preg_match('/BOX/si', $suburb) ) {
      $error = true;
    } else if ( preg_match('/POBOX/si', $suburb) ) {
      $error = true;
    } else if ( preg_match('/P\.O\./si', $suburb) ) {
      $error = true;
    } else if ( preg_match('/P\.O/si', $suburb) ) {
      $error = true;
    } else if ( preg_match('/PO\./si', $suburb) ) {
      $error = true;
    }

    if ($error) {
      $this->enabled = false;
    }
}
// eof: block PO BOX addresses in $order->delivery['street_address'] or $order->delivery['suburb']

      if ( ($this->enabled == true) && ((int)MODULE_SHIPPING_UPS_ZONE > 0) ) {

Save your changes and upload the file to your server making sure that you overwrite the file already on your server. Test by trying to checkout in your zen cart using the UPS shipping module and a PO Box shipping address.

If you need help with your zen cart web site please contact us for a quote.

zen cart plus picaflor azul equals success

Leave a Reply