Add LV postcode formatting and tests
This commit is contained in:
parent
33cca70beb
commit
474494dcab
|
@ -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 );
|
||||
|
|
|
@ -801,6 +801,12 @@ class WC_Tests_Formatting_Functions extends WC_Unit_Test_Case {
|
|||
// JP postcode.
|
||||
$this->assertEquals( '999-9999', wc_format_postcode( '9999999', 'JP' ) );
|
||||
|
||||
// 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' ) );
|
||||
|
||||
// Test empty NL postcode.
|
||||
$this->assertEquals( '', wc_format_postcode( '', 'NL' ) );
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue