Author Topic: USPS V5 - ZIP+4 Error with fix  (Read 2754 times)

piperpilot

  • Beginner
  • *
  • Posts: 44
USPS V5 - ZIP+4 Error with fix
« on: May 02, 2011, 22:55:14 pm »
I was experiencing a large amount of my customers entering ZIP+4 addresses which returns a very cryptic message about not being able to ship via USPS.  I understand from Reggie that this is because USPS doesn't support ZIP+4 in their zip code handling in the API.

I thought about limiting the entry field for the address, but this would screw up international addresses and postal codes.  So here is the better fix.  Hopefully Reggie will pick this up and put it as part of the standard files...

In uspsv5.php (new version), around line 340...

Look for:

Code: [Select]
if($dest_zip==''){
uspsv5::debugLog("uspsv5::get_rates_array() - invalid destination country.");
return null;
}

After that insert the following code snippet:

Code: [Select]

// Check to make sure the user didn't enter a ZIP+4 Zip Code, its not supported
if((strlen($dest_zip) > 5) && ($this->domestic===true)) {
$dest_zip = substr($dest_zip, 0, 5);
}

This makes a domestic zip code only 5 digits long.

Hope it helps someone else.

PiperPilot

snelson

  • Beginner
  • *
  • Posts: 17
Re: USPS V5 - ZIP+4 Error with fix
« Reply #1 on: August 09, 2011, 08:41:20 am »
I made this code correction and it worked perfectly.
Thanks