Zen Cart Logo
Forums / Addon Shipping Modules / Disable UPS for PO Box addresses

Disable UPS for PO Box addresses

Views: 1,927

Results 1 to 8 of 8
6 Aug 2014, 2:03 AM
#1
danielle avatar

danielle

Totally Zenned

Join Date:
Oct 2004
Posts:
973
Plugin Contributions:
0

Disable UPS for PO Box addresses

I know there is a mod to ban PO boxes altogether, but is there a way to disable a specific shipping method when the address is a po box?

TIA!

6 Aug 2014, 1:07 PM
#2
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Disable UPS for PO Box addresses

You could try customizing the code in:
/includes/modules/shipping/ups.php

with the code in RED:

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

[B]// 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']
[/B]
      if ( ($this->enabled == true) && ((int)MODULE_SHIPPING_UPS_ZONE > 0) ) {
6 Aug 2014, 5:06 PM
#3
danielle avatar

danielle

Totally Zenned

Join Date:
Oct 2004
Posts:
973
Plugin Contributions:
0

Re: Disable UPS for PO Box addresses

Thank you, I tried it in flat.php as a test because UPS isn't actually installed yet, and kept getting this log error:

PHP Parse error: syntax error, unexpected 'if' (T_IF), expecting function (T_FUNCTION) in /***/public_html/includes/modules/shipping/flat.php on line 69

This is that section of code in flat.php, with line 69 highlighted in red:

      // disable only when entire cart is free shipping
      if (zen_get_shipping_enabled($this->code)) {
        $this->enabled = ((MODULE_SHIPPING_FLAT_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']   
    
[B]      if ( ($this->enabled == true) && ((int)MODULE_SHIPPING_FLAT_ZONE > 0) ) {[/B]

Ajeh:

You could try customizing the code in:
/includes/modules/shipping/ups.php

with the code in RED:

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

[B]// 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']
[/B]
if ( ($this->enabled == true) && ((int)MODULE_SHIPPING_UPS_ZONE > 0) ) {

6 Aug 2014, 5:56 PM
#4
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Disable UPS for PO Box addresses

Check the code that I posted as your code looks like you missed a chunk ...

6 Aug 2014, 6:08 PM
#5
danielle avatar

danielle

Totally Zenned

Join Date:
Oct 2004
Posts:
973
Plugin Contributions:
0

Re: Disable UPS for PO Box addresses

Hmmm it looks identical to me. What chunk did I miss?

Ajeh:

Check the code that I posted as your code looks like you missed a chunk ...

6 Aug 2014, 6:11 PM
#6
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Disable UPS for PO Box addresses

I see what looks so odd, you have all the code on 1 line for:

    // 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'];

Try putting the code like I have it as it looks like you have turned the start of the code into a comment ...

25 Sep 2014, 3:53 PM
#7
wheat avatar

wheat

New Zenner

Join Date:
Oct 2006
Posts:
62
Plugin Contributions:
0

Re: Disable UPS for PO Box addresses

Just something to think about, but banning PO Boxes MAY NO LONGER be a good idea.

First, there are an increasing number of places in the US where a customer may not have a street address - and with the advent of USPS allowing use of the PO Street Address with a "UNIT" number - to receive UPS and FedEx and other non-govt common carrier deliveries - it might be worth rethinking if it is desirable to block PO Boxes - either you or the consumer can "translate" the address: i.e,

My "PO BOX 1232" Sykesville MD 21784
address could be

1363 Progress Way Unit 1232
Sykesville MD 21784

and deliveries would be accepted by the USPS

This link has been useful for purposes of finding street addresses when needed - preferable (to me) than placing one more obstacle in front the consumer completely/placing/buying -

as I said, just something to consider

1 Nov 2014, 1:19 PM
#8
fourpaws avatar

fourpaws

New Zenner

Join Date:
Apr 2013
Location:
Johannesburg, South Africa
Posts:
13
Plugin Contributions:
0

Re: Disable UPS for PO Box addresses

Thanks for this, its solved a few queries in my shop.