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:
commit
2d991ff1d1
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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' ) );
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue