Merge pull request #11890 from woothemes/support-new-us-postcodes

Added support for the new US postcode format with 9 digits
This commit is contained in:
Claudio Sanches 2016-09-09 15:07:12 -03:00 committed by GitHub
commit 2d991ff1d1
2 changed files with 10 additions and 4 deletions

View File

@ -685,13 +685,16 @@ function wc_format_postcode( $postcode, $country ) {
break;
case 'BR' :
case 'PL' :
$postcode = trim( substr_replace( $postcode, '-', -3, 0 ) );
$postcode = substr_replace( $postcode, '-', -3, 0 );
break;
case 'JP' :
$postcode = trim( substr_replace( $postcode, '-', 3, 0 ) );
$postcode = substr_replace( $postcode, '-', 3, 0 );
break;
case 'PT' :
$postcode = trim( substr_replace( $postcode, '-', 4, 0 ) );
$postcode = substr_replace( $postcode, '-', 4, 0 );
break;
case 'US' :
$postcode = rtrim( substr_replace( $postcode, '-', 5, 0 ), '-' );
break;
}

View File

@ -615,9 +615,12 @@ class WC_Tests_Formatting_Functions extends WC_Unit_Test_Case {
*/
public function test_wc_format_postcode() {
// generic postcode
// Generic postcode
$this->assertEquals( '02111', wc_format_postcode( ' 02111 ', 'US' ) );
// US 9-digit postcode
$this->assertEquals( '02111-9999', wc_format_postcode( ' 021119999 ', 'US' ) );
// UK postcode
$this->assertEquals( 'PCRN 1ZZ', wc_format_postcode( 'pcrn1zz', 'GB' ) );
}