Commit 56412136da5 for woocommerce
commit 56412136da5d20479ced836cf891ace04cf76807
Author: Chris Lilitsas <1105590+xristos3490@users.noreply.github.com>
Date: Tue Jul 14 12:01:36 2026 +0300
Fix: Respect store decimal separator in product CSV weight & dimensions import (#66205)
fix: respect store decimal separator in product CSV weight import
diff --git a/plugins/woocommerce/changelog/38116-fix-csv-import-weight-decimal-separator b/plugins/woocommerce/changelog/38116-fix-csv-import-weight-decimal-separator
new file mode 100644
index 00000000000..c2ff09c0538
--- /dev/null
+++ b/plugins/woocommerce/changelog/38116-fix-csv-import-weight-decimal-separator
@@ -0,0 +1,4 @@
+Significance: patch
+Type: fix
+
+Product CSV importer: respect the store's decimal separator setting when parsing weight and dimensions, so comma-separated values (e.g. "1,5") are no longer discarded.
diff --git a/plugins/woocommerce/includes/import/class-wc-product-csv-importer.php b/plugins/woocommerce/includes/import/class-wc-product-csv-importer.php
index 0c635e874f9..864f7be875f 100644
--- a/plugins/woocommerce/includes/import/class-wc-product-csv-importer.php
+++ b/plugins/woocommerce/includes/import/class-wc-product-csv-importer.php
@@ -373,7 +373,10 @@ class WC_Product_CSV_Importer extends WC_Product_Importer {
// Remove the ' prepended to fields that start with - if needed.
$value = $this->unescape_data( $value );
- return floatval( $value );
+ // Use wc_format_decimal() rather than floatval() so the store's decimal separator
+ // setting is respected (e.g. a comma-separated weight like "1,5"). This mirrors how
+ // price fields are parsed above and how the product setters normalize these values.
+ return (float) wc_format_decimal( $value );
}
/**
diff --git a/plugins/woocommerce/tests/php/includes/importer/class-wc-product-csv-importer-test.php b/plugins/woocommerce/tests/php/includes/importer/class-wc-product-csv-importer-test.php
index 379e14643ef..52a39c1a736 100644
--- a/plugins/woocommerce/tests/php/includes/importer/class-wc-product-csv-importer-test.php
+++ b/plugins/woocommerce/tests/php/includes/importer/class-wc-product-csv-importer-test.php
@@ -24,6 +24,15 @@ class WC_Product_CSV_Importer_Test extends \WC_Unit_Test_Case {
require_once $bootstrap->plugin_dir . '/includes/admin/importers/class-wc-product-csv-importer-controller.php';
}
+ /**
+ * Clean up after each test.
+ */
+ public function tearDown(): void {
+ remove_all_filters( 'wc_get_price_decimal_separator' );
+
+ parent::tearDown();
+ }
+
/**
* @testdox variations need to set the status back to published if parent product is a draft
*/
@@ -246,4 +255,50 @@ class WC_Product_CSV_Importer_Test extends \WC_Unit_Test_Case {
wc_delete_attribute( $color_attr_id );
wc_delete_attribute( $size_attr_id );
}
+
+ /**
+ * @testdox parse_float_field should respect the store's decimal separator setting (issue #38116).
+ * @dataProvider provider_parse_float_field_decimal_separator
+ *
+ * @param string $decimal_sep The store's decimal separator setting.
+ * @param string $value The raw CSV value to parse.
+ * @param float $expected The expected parsed float.
+ */
+ public function test_parse_float_field_respects_decimal_separator( string $decimal_sep, string $value, float $expected ) {
+ add_filter( 'wc_get_price_decimal_separator', fn() => $decimal_sep );
+
+ $importer = new WC_Product_CSV_Importer( __DIR__ . '/sample.csv' );
+ $result = $importer->parse_float_field( $value );
+
+ $this->assertSame( $expected, $result, "Expected '{$value}' to parse to {$expected} with '{$decimal_sep}' as the decimal separator." );
+ }
+
+ /**
+ * Data provider for test_parse_float_field_respects_decimal_separator.
+ *
+ * @return array
+ */
+ public function provider_parse_float_field_decimal_separator(): array {
+ return array(
+ 'comma separator, comma value' => array( ',', '1,5', 1.5 ),
+ 'comma separator, sub-one value' => array( ',', '0,5', 0.5 ),
+ 'period separator, period value' => array( '.', '1.5', 1.5 ),
+ 'comma separator, integer value' => array( ',', '10', 10.0 ),
+
+ // With a period separator the comma is treated as a grouping separator and
+ // stripped, mirroring how price fields (which also use wc_format_decimal) behave.
+ // A comma-decimal CSV therefore requires the store's separator to be set to comma.
+ 'period separator, comma value' => array( '.', '0,5', 5.0 ),
+ 'period separator, comma+int' => array( '.', '1,5', 15.0 ),
+ );
+ }
+
+ /**
+ * @testdox parse_float_field should return an empty string unchanged.
+ */
+ public function test_parse_float_field_returns_empty_string_unchanged() {
+ $importer = new WC_Product_CSV_Importer( __DIR__ . '/sample.csv' );
+
+ $this->assertSame( '', $importer->parse_float_field( '' ), 'Empty values should be returned unchanged.' );
+ }
}