Commit 6fcb578d7df for woocommerce
commit 6fcb578d7dfe3ec58cfc222296fa7648a1067cd9
Author: Sakri Koskimies <sakri.koskimies@hotmail.com>
Date: Wed Aug 12 18:18:16 2026 +0300
fix: Add postcode validation for Latvia (#67460)
* fix: Add postcode validation for Latvia
* fix: Anchor LV postcode pattern to reject a trailing newline
* docs: Clarify Latvia postcode changelog wording
---------
Co-authored-by: Sakri Koskimies <sakri.koskimies@avenla.fi>
diff --git a/plugins/woocommerce/changelog/67459-lv-postcode-validation b/plugins/woocommerce/changelog/67459-lv-postcode-validation
new file mode 100644
index 00000000000..d376d3afef1
--- /dev/null
+++ b/plugins/woocommerce/changelog/67459-lv-postcode-validation
@@ -0,0 +1,4 @@
+Significance: patch
+Type: fix
+
+Add postcode validation for Latvia, which previously accepted invalid values.
diff --git a/plugins/woocommerce/includes/class-wc-validation.php b/plugins/woocommerce/includes/class-wc-validation.php
index 9ab923e124e..330dd93acc4 100644
--- a/plugins/woocommerce/includes/class-wc-validation.php
+++ b/plugins/woocommerce/includes/class-wc-validation.php
@@ -143,6 +143,9 @@ class WC_Validation {
case 'LI':
$valid = (bool) preg_match( '/^(94[8-9][0-9])$/', $postcode );
break;
+ case 'LV':
+ $valid = (bool) preg_match( '/^(?:LV-)?[1-9][0-9]{3}\z/i', $postcode );
+ break;
default:
$valid = true;
break;
diff --git a/plugins/woocommerce/tests/php/includes/class-wc-validation-test.php b/plugins/woocommerce/tests/php/includes/class-wc-validation-test.php
index 5f8798a56e1..640ec71c6b3 100644
--- a/plugins/woocommerce/tests/php/includes/class-wc-validation-test.php
+++ b/plugins/woocommerce/tests/php/includes/class-wc-validation-test.php
@@ -87,7 +87,19 @@ class WC_Validation_Test extends \WC_Unit_Test_Case {
array( false, '948A', 'LI' ),
);
- return array_merge( $cz, $se, $li );
+ $lv = array(
+ array( true, 'LV-1050', 'LV' ),
+ array( true, 'lv-1050', 'LV' ),
+ array( true, '1050', 'LV' ),
+ array( false, 'LV-0123', 'LV' ),
+ array( false, 'LV-105', 'LV' ),
+ array( false, '10500', 'LV' ),
+ array( false, 'ZZ-1050', 'LV' ),
+ array( false, 'LV-ABCD', 'LV' ),
+ array( false, "LV-1050\n", 'LV' ),
+ );
+
+ return array_merge( $cz, $se, $li, $lv );
}
/**