Merge pull request #32799 from woocommerce/pr/31788
Fix Latvian postcodes formatting
This commit is contained in:
commit
e2489416b9
|
@ -0,0 +1,4 @@
|
|||
Significance: minor
|
||||
Type: add
|
||||
|
||||
Add formatting rules for Latvian postcodes.
|
|
@ -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 );
|
||||
|
|
|
@ -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' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue