Commit 46052fcf2d6 for woocommerce
commit 46052fcf2d67ba85f61d6c4db7437b1896963ba8
Author: Oleksandr Aratovskyi <79862886+oaratovskyi@users.noreply.github.com>
Date: Wed Apr 8 12:50:14 2026 +0300
Fix fatal error in PaymentsProviders when gateway order has integer keys (#64051)
* fix(payments): strip non-string keys from order map during normalization
The `woocommerce_gateway_order` option can contain legacy integer array
keys from older WooCommerce versions or corrupt data. When
`is_offline_group_last()` iterates over the order map and passes these
integer keys to `is_offline_payment_method(string $id)`, PHP 8's
strict_types causes a TypeError crash on the Payments settings page.
Filter out non-string keys in `Utils::order_map_normalize()` — the
central normalization entry point — so all downstream consumers are
protected. Integer keys don't correspond to any real gateway ID and are
already ignored by the legacy `WC_Payment_Gateways` code.
Refs WOOPLUG-6508
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* Add changefile(s) from automation for the following project(s): woocommerce
---------
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-authored-by: woocommercebot <woocommercebot@users.noreply.github.com>
diff --git a/plugins/woocommerce/changelog/64051-fix-WOOPLUG-6508-fatal-error-order-map-integer-keys b/plugins/woocommerce/changelog/64051-fix-WOOPLUG-6508-fatal-error-order-map-integer-keys
new file mode 100644
index 00000000000..acad5463578
--- /dev/null
+++ b/plugins/woocommerce/changelog/64051-fix-WOOPLUG-6508-fatal-error-order-map-integer-keys
@@ -0,0 +1,4 @@
+Significance: patch
+Type: fix
+
+Fix fatal error on Payments settings page when `woocommerce_gateway_order` option contains legacy integer keys.
\ No newline at end of file
diff --git a/plugins/woocommerce/src/Internal/Admin/Settings/Utils.php b/plugins/woocommerce/src/Internal/Admin/Settings/Utils.php
index 6900f35bf5d..a4ec3a77940 100644
--- a/plugins/woocommerce/src/Internal/Admin/Settings/Utils.php
+++ b/plugins/woocommerce/src/Internal/Admin/Settings/Utils.php
@@ -163,6 +163,13 @@ class Utils {
* @return array The normalized order map.
*/
public static function order_map_normalize( array $order_map ): array {
+ // Remove entries with non-string keys (legacy/corrupt data).
+ $order_map = array_filter(
+ $order_map,
+ fn( $key ) => is_string( $key ),
+ ARRAY_FILTER_USE_KEY
+ );
+
asort( $order_map );
return array_flip( array_keys( $order_map ) );
diff --git a/plugins/woocommerce/tests/php/src/Internal/Admin/Settings/UtilsTest.php b/plugins/woocommerce/tests/php/src/Internal/Admin/Settings/UtilsTest.php
index 7d840fd1c78..e6539a4d660 100644
--- a/plugins/woocommerce/tests/php/src/Internal/Admin/Settings/UtilsTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/Admin/Settings/UtilsTest.php
@@ -1462,6 +1462,37 @@ class UtilsTest extends WC_Unit_Test_Case {
'provider3' => 2,
),
),
+ 'integer keys are removed' => array(
+ array(
+ 0 => 0,
+ 'provider1' => 1,
+ 'provider2' => 2,
+ ),
+ array(
+ 'provider1' => 0,
+ 'provider2' => 1,
+ ),
+ ),
+ 'only integer keys' => array(
+ array(
+ 0 => 0,
+ 1 => 1,
+ 2 => 2,
+ ),
+ array(),
+ ),
+ 'mixed integer and string keys' => array(
+ array(
+ 0 => 5,
+ 'provider1' => 10,
+ 1 => 15,
+ 'provider2' => 20,
+ ),
+ array(
+ 'provider1' => 0,
+ 'provider2' => 1,
+ ),
+ ),
);
}