Commit 6ada707ac46 for woocommerce
commit 6ada707ac461e6fdb69d655bd0f4cb1c45f47464
Author: Ahmed <ahmed.el.azzabi@automattic.com>
Date: Tue Mar 31 09:57:16 2026 +0100
Skip suggestion matching for offline payment methods (#63930)
* Skip suggestion matching for offline payment methods
Offline PMs (BACS, COD, Cheque) can never have extension suggestions or
incentives. Add an early return in enhance_payment_gateway_details() to
skip the unnecessary suggestion lookup, avoiding wasted processing and
indirect external API calls for these gateways.
Fixes WOOPRD-2473.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* Add changefile(s) from automation for the following project(s): woocommerce
* Use WC_Gateway_BACS::ID constant in offline PM test
Replace hardcoded 'bacs' string with the canonical constant for
consistency with the rest of the test file.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
---------
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/63930-fix-skip-incentive-check-offline-payment-methods b/plugins/woocommerce/changelog/63930-fix-skip-incentive-check-offline-payment-methods
new file mode 100644
index 00000000000..7132b83319d
--- /dev/null
+++ b/plugins/woocommerce/changelog/63930-fix-skip-incentive-check-offline-payment-methods
@@ -0,0 +1,4 @@
+Significance: minor
+Type: dev
+
+Skip unnecessary extension suggestion lookup for offline payment methods in enhance_payment_gateway_details().
\ No newline at end of file
diff --git a/plugins/woocommerce/src/Internal/Admin/Settings/PaymentsProviders.php b/plugins/woocommerce/src/Internal/Admin/Settings/PaymentsProviders.php
index 54916f7a6d9..9e9125bf4c8 100644
--- a/plugins/woocommerce/src/Internal/Admin/Settings/PaymentsProviders.php
+++ b/plugins/woocommerce/src/Internal/Admin/Settings/PaymentsProviders.php
@@ -1298,6 +1298,12 @@ class PaymentsProviders {
// We discriminate between offline payment methods and gateways.
$gateway_details['_type'] = $this->is_offline_payment_method( $payment_gateway->id ) ? self::TYPE_OFFLINE_PM : self::TYPE_GATEWAY;
+ // Offline payment methods don't have extension suggestions or incentives.
+ // Skip the suggestion matching to avoid unnecessary processing.
+ if ( self::TYPE_OFFLINE_PM === $gateway_details['_type'] ) {
+ return $gateway_details;
+ }
+
$plugin_slug = $gateway_details['plugin']['slug'];
// The payment gateway plugin might use a non-standard directory name.
// Try to normalize it to the common slug to avoid false negatives when matching.
diff --git a/plugins/woocommerce/tests/php/src/Internal/Admin/Settings/PaymentsProvidersTest.php b/plugins/woocommerce/tests/php/src/Internal/Admin/Settings/PaymentsProvidersTest.php
index 31a68ac68c5..a40fb6a1ac3 100644
--- a/plugins/woocommerce/tests/php/src/Internal/Admin/Settings/PaymentsProvidersTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/Admin/Settings/PaymentsProvidersTest.php
@@ -1115,6 +1115,43 @@ class PaymentsProvidersTest extends WC_Unit_Test_Case {
$this->assertSame( ExtensionSuggestions::PAYPAL_FULL_STACK, $gateway_details['_suggestion_id'], 'Suggestion ID should match' );
}
+ /**
+ * Test that get_payment_gateway_details skips suggestion matching for offline payment methods.
+ *
+ * Offline PMs (BACS, COD, Cheque) don't have extension suggestions or incentives.
+ * The suggestion lookup should be skipped entirely for them.
+ */
+ public function test_get_payment_gateway_details_skips_suggestion_matching_for_offline_pms() {
+ // Arrange.
+ $fake_gateway = new FakePaymentGateway(
+ WC_Gateway_BACS::ID,
+ array(
+ 'enabled' => true,
+ 'title' => 'Direct bank transfer',
+ 'method_title' => 'Direct bank transfer',
+ 'description' => 'Make your payment directly into our bank account.',
+ 'method_description' => 'Take payments in person via BACS.',
+ 'plugin_slug' => 'woocommerce',
+ 'plugin_file' => 'woocommerce/woocommerce.php',
+ ),
+ );
+
+ // The suggestion service should never be called for offline PMs.
+ $this->mock_extension_suggestions
+ ->expects( $this->never() )
+ ->method( 'get_by_plugin_slug' );
+
+ // Act.
+ $gateway_details = $this->sut->get_payment_gateway_details( $fake_gateway, 0, 'US' );
+
+ // Assert that the gateway is correctly identified as an offline PM.
+ $this->assertSame( PaymentsProviders::TYPE_OFFLINE_PM, $gateway_details['_type'] );
+
+ // Assert that no suggestion-derived fields are present.
+ $this->assertArrayNotHasKey( '_suggestion_id', $gateway_details );
+ $this->assertArrayNotHasKey( '_incentive', $gateway_details );
+ }
+
/**
* Test getting the plugin slug of a payment gateway instance.
*/