Merge pull request #32799 from woocommerce/pr/31788

Fix Latvian postcodes formatting
This commit is contained in:
Vedanshu Jain 2022-04-27 13:26:18 +05:30 committed by GitHub
commit e2489416b9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 0 deletions

View File

@ -0,0 +1,4 @@
Significance: minor
Type: add
Add formatting rules for Latvian postcodes.

View File

@ -993,6 +993,11 @@ function wc_format_postcode( $postcode, $country ) {
case 'NL':
$postcode = substr_replace( $postcode, ' ', 4, 0 );
break;
case 'LV':
if ( preg_match( '/(?:LV)?-?(\d+)/i', $postcode, $matches ) ) {
$postcode = count( $matches ) >= 2 ? "LV-$matches[1]" : $postcode;
}
break;
}
return apply_filters( 'woocommerce_format_postcode', trim( $postcode ), $country );

View File

@ -803,6 +803,12 @@ class WC_Tests_Formatting_Functions extends WC_Unit_Test_Case {
// Test empty NL postcode.
$this->assertEquals( '', wc_format_postcode( '', 'NL' ) );
// Test LV postcode without mandatory country code.
$this->assertEquals( 'LV-1337', wc_format_postcode( '1337', 'LV' ) );
// Test LV postcode with incorrect format (no dash).
$this->assertEquals( 'LV-1337', wc_format_postcode( 'lv1337', 'LV' ) );
}
/**