Commit c3b87ea058b for woocommerce

commit c3b87ea058b84708b91d3d4871b63bd199d74c3b
Author: Luigi Teschio <gigitux@gmail.com>
Date:   Tue Dec 1 10:53:17 2026 +0100

    Reject matching price separators in General settings (#71602)

    * Reject matching price separators in General settings

    * Add changelog entry for matching price separators

diff --git a/plugins/woocommerce/changelog/fix-matching-price-separators b/plugins/woocommerce/changelog/fix-matching-price-separators
new file mode 100644
index 00000000000..199ff150336
--- /dev/null
+++ b/plugins/woocommerce/changelog/fix-matching-price-separators
@@ -0,0 +1,4 @@
+Significance: patch
+Type: fix
+
+Keep the previous price separators and show a warning when the submitted separators match.
diff --git a/plugins/woocommerce/includes/admin/class-wc-admin-settings.php b/plugins/woocommerce/includes/admin/class-wc-admin-settings.php
index 8e35044d694..5cc986594b4 100644
--- a/plugins/woocommerce/includes/admin/class-wc-admin-settings.php
+++ b/plugins/woocommerce/includes/admin/class-wc-admin-settings.php
@@ -1138,6 +1138,8 @@ if ( ! class_exists( 'WC_Admin_Settings', false ) ) :
 				do_action( 'woocommerce_update_option', $option );
 			}

+			$update_options = self::validate_price_separator_settings( $update_options );
+
 			// Save all options in our array.
 			foreach ( $update_options as $name => $value ) {
 				update_option( $name, $value, $autoload_options[ $name ] ? 'yes' : 'no' );
@@ -1146,6 +1148,31 @@ if ( ! class_exists( 'WC_Admin_Settings', false ) ) :
 			return true;
 		}

+		/**
+		 * Keep the stored price separators if the sanitized pair would display the same character.
+		 *
+		 * @param array $options Sanitized options to save.
+		 * @return array Options to save after validation.
+		 */
+		private static function validate_price_separator_settings( array $options ): array {
+			$thousand_separator = $options['woocommerce_price_thousand_sep'] ?? null;
+			$decimal_separator  = $options['woocommerce_price_decimal_sep'] ?? null;
+			if ( ! is_string( $thousand_separator ) || ! is_string( $decimal_separator ) ) {
+				return $options;
+			}
+
+			// An empty thousand separator disables grouping. An empty decimal separator displays as a period.
+			$thousand_separator = html_entity_decode( stripslashes( $thousand_separator ), ENT_QUOTES | ENT_HTML5, 'UTF-8' );
+			$decimal_separator  = html_entity_decode( $decimal_separator ? stripslashes( $decimal_separator ) : '.', ENT_QUOTES | ENT_HTML5, 'UTF-8' );
+
+			if ( '' !== $thousand_separator && $thousand_separator === $decimal_separator ) {
+				unset( $options['woocommerce_price_thousand_sep'], $options['woocommerce_price_decimal_sep'] );
+				self::add_error( __( 'Use different characters for the thousand and decimal separators. Your previous separators are still in use.', 'woocommerce' ) );
+			}
+
+			return $options;
+		}
+
 		/**
 		 * Checks which method we're using to serve downloads.
 		 *
diff --git a/plugins/woocommerce/tests/php/includes/admin/class-wc-admin-settings-test.php b/plugins/woocommerce/tests/php/includes/admin/class-wc-admin-settings-test.php
index 581d657b385..0f3ca02abc2 100644
--- a/plugins/woocommerce/tests/php/includes/admin/class-wc-admin-settings-test.php
+++ b/plugins/woocommerce/tests/php/includes/admin/class-wc-admin-settings-test.php
@@ -249,6 +249,50 @@ class WC_Admin_Settings_Test extends WC_Unit_Test_Case {
 		$this->assertSame( 'bold text', get_option( $option_name ), 'Text fields should still go through wc_clean' );
 	}

+	/**
+	 * @testdox Should keep the saved price separators and render a standard settings error when the submitted separators match.
+	 *
+	 * @testWith [" ", " ", true]
+	 *           [".", ",", false]
+	 *
+	 * @param string $thousand_separator Submitted thousand separator.
+	 * @param string $decimal_separator  Submitted decimal separator.
+	 * @param bool   $expects_error      Whether the pair should be rejected.
+	 */
+	public function test_save_fields_validates_price_separator_pair( string $thousand_separator, string $decimal_separator, bool $expects_error ): void {
+		update_option( 'woocommerce_price_thousand_sep', ',' );
+		update_option( 'woocommerce_price_decimal_sep', '.' );
+		$settings = ( new WC_Settings_General() )->get_settings_for_section( '' );
+		$data     = array(
+			'woocommerce_price_thousand_sep' => $thousand_separator,
+			'woocommerce_price_decimal_sep'  => $decimal_separator,
+			'woocommerce_price_num_decimals' => '3',
+		);
+
+		$errors = new ReflectionProperty( WC_Admin_Settings::class, 'errors' );
+		$errors->setAccessible( true );
+		$previous_errors = $errors->getValue();
+		$errors->setValue( null, array() );
+		ob_start();
+		try {
+			WC_Admin_Settings::save_fields( $settings, $data );
+			WC_Admin_Settings::show_messages();
+			$notices = (string) ob_get_contents();
+		} finally {
+			ob_end_clean();
+			$errors->setValue( null, $previous_errors );
+		}
+
+		$this->assertSame( $expects_error ? ',' : $thousand_separator, get_option( 'woocommerce_price_thousand_sep' ), 'Unexpected saved thousand separator.' );
+		$this->assertSame( $expects_error ? '.' : $decimal_separator, get_option( 'woocommerce_price_decimal_sep' ), 'Unexpected saved decimal separator.' );
+		$this->assertSame( 3, wc_get_price_decimals(), 'Other currency settings should still be saved.' );
+		if ( $expects_error ) {
+			$this->assertStringContainsString( '<div id="message" class="error inline"><p><strong>Use different characters for the thousand and decimal separators. Your previous separators are still in use.</strong></p></div>', $notices );
+		} else {
+			$this->assertStringNotContainsString( 'class="error inline"', $notices, 'Valid separators should not render a settings error.' );
+		}
+	}
+
 	/**
 	 * @testdox Should redirect to the requested Settings UI destination after saving.
 	 */