Commit 869a463344f for woocommerce

commit 869a463344f4c769d007a05a2385a77e0e362d3c
Author: Vlad Olaru <vlad.olaru@automattic.com>
Date:   Thu Dec 3 13:13:15 2026 +0200

    Stop background WooCommerce.com suggestion requests when marketplace suggestions are off (#71698)

    * fix: Skip marketplace promotions when suggestions are turned off

    The twice-daily `woocommerce_marketplace_cron_fetch_promotions` event
    requested promotions from WooCommerce.com even when the merchant had
    unchecked "Display suggestions within WooCommerce". Only the
    `woocommerce_marketplace_suppress_promotions` filter could stop it.

    Treat the setting being off the same way as that filter, in all three
    places that read it: the fetch, the cached promotions used by the
    Marketplace app and the Orders promo card, and the Extensions menu
    badge. Gating the cached promotions too means a store that opts out
    stops seeing them at once, instead of after the next fetch empties the
    cache (up to 12 hours, or 24 if cron runs late).

    The filter is still applied first on every path, so callbacks run
    exactly as before.

    Refs #55894

    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

    * fix: Skip daily suggestion list refresh when suggestions are off

    The `wc_admin_daily` event primes the payment gateway suggestions and
    free extensions caches from WooCommerce.com. It did so even when
    "Display suggestions within WooCommerce" was unchecked, although every
    reader of those lists falls back to the bundled defaults then, so the
    downloads were never used.

    Return early from the refresh when the setting is `no`, matching the
    check those readers use.

    Refs #55894

    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

    * fix: Say that payment provider offers ignore the suggestions setting

    WooPayments incentive offers are still requested when "Display
    suggestions within WooCommerce" is unchecked; that is a deliberate
    product decision. The help text gave no hint of it, so merchants who
    opted out were surprised to see the request.

    Extend the help text to say payment provider offers are not affected,
    update the settings API test that asserts it, and add the changelog
    entry for the branch.

    Refs #55894

    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

    * test: Cover the suppression filter in suggestions opt-out tests

    Review of the branch found that no test made
    `woocommerce_marketplace_suppress_promotions` return true, so a helper
    that dropped the filter's result from its check would still pass.

    Add a suppressed row to both promotions tests. Make the poller test
    match version-agnostic endpoint paths and cover an unset option, and
    assign the public `$locale` property directly instead of through
    reflection.

    Refs #55894

    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

    * refactor: Trim the promotions suppression helper and its docblocks

    The suppression rule was spelled out in three docblocks, and the
    helper kept a local only to order the filter before the option read,
    which `||` already guarantees.

    Return the combined check directly, point the two callers' docblocks
    at the helper, and drop an Events comment line that implied the
    `'no' ===` form differs from `!== 'yes'` for an unset option.

    Refs #55894

    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

    * test: Count requests with the base test case's HTTP recorder

    Both opt-out tests registered their own `pre_http_request` counter,
    duplicating what `WP_HTTP_TestCase` (the parent of
    `WC_Unit_Test_Case`) already records in `$this->http_requests`.

    Answer requests through `$this->http_responder` and count the
    recorded URLs instead. The poller test's two expectation columns were
    always equal, so it now takes one.

    Refs #55894

    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

    * fix: Scope the payment offers note to the Payments settings page

    The "Show Suggestions" help text said payment provider offers are not
    affected by the setting. That holds only for the Settings > Payments
    page. WcPayWelcomePage::has_incentive() also reads
    woocommerce_show_marketplace_suggestions, so with the setting off the
    onboarding Payments task stops linking to the WooPayments incentive and
    the PaymentsRemindMeLater and PaymentsMoreInfoNeeded notes stay hidden.

    Name the page the note applies to, and update the settings API test
    string to match.

    Refs #55894

    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

    * test: Restore the promotions locale after each promotions test

    The cached promotions test sets the static
    WC_Admin_Marketplace_Promotions::$locale and never put it back, so the
    value leaked into later tests in the same process. Save it in setUp and
    restore it in tearDown. The property is a typed static, which cannot
    return to uninitialized, so only a value that was set before the test
    is restored.

    Refs #55894

    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

    * test: Rename the saved promotions locale property

    The promotions test saved the locale in a private $original_locale
    property. The WordPress test library in WP 7.2 (WP_UnitTestCase_Base)
    adds a protected property with the same name, so on WP pre-release the
    test class fatals on load: "Access level to ...::$original_locale must
    be protected". Name the property after what it holds instead, so it
    cannot clash with the base class.

    Refs #55894

    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

    ---------

    Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

diff --git a/plugins/woocommerce/changelog/fix-55894-marketplace-suggestions-opt-out b/plugins/woocommerce/changelog/fix-55894-marketplace-suggestions-opt-out
new file mode 100644
index 00000000000..fa6a316973c
--- /dev/null
+++ b/plugins/woocommerce/changelog/fix-55894-marketplace-suggestions-opt-out
@@ -0,0 +1,4 @@
+Significance: patch
+Type: fix
+
+Stop fetching marketplace promotions and suggestion lists from WooCommerce.com when "Display suggestions within WooCommerce" is off.
diff --git a/plugins/woocommerce/includes/admin/class-wc-admin-marketplace-promotions.php b/plugins/woocommerce/includes/admin/class-wc-admin-marketplace-promotions.php
index e4ded33b219..662c0bcef47 100644
--- a/plugins/woocommerce/includes/admin/class-wc-admin-marketplace-promotions.php
+++ b/plugins/woocommerce/includes/admin/class-wc-admin-marketplace-promotions.php
@@ -130,17 +130,12 @@ class WC_Admin_Marketplace_Promotions {

 	/**
 	 * Get active Marketplace promotions from the transient.
-	 * Use `woocommerce_marketplace_suppress_promotions` filter to suppress promotions.
+	 * Returns none when promotions are suppressed (see `are_promotions_suppressed()`).
 	 *
 	 * @since 9.0
 	 */
 	public static function get_active_promotions() {
-		/**
-		 * Filter to suppress the requests for and showing of marketplace promotions.
-		 *
-		 * @since 8.8
-		 */
-		if ( apply_filters( 'woocommerce_marketplace_suppress_promotions', false ) ) {
+		if ( self::are_promotions_suppressed() ) {
 			return array();
 		}

@@ -155,6 +150,20 @@ class WC_Admin_Marketplace_Promotions {
 		return self::filter_out_inactive_promotions( $promotions );
 	}

+	/**
+	 * Whether promotions should be neither fetched nor shown: the suppression filter says so, or marketplace suggestions are off.
+	 *
+	 * @return bool
+	 */
+	private static function are_promotions_suppressed(): bool {
+		/**
+		 * Filter to suppress the requests for and showing of marketplace promotions.
+		 *
+		 * @since 8.8
+		 */
+		return apply_filters( 'woocommerce_marketplace_suppress_promotions', false ) || 'no' === get_option( 'woocommerce_show_marketplace_suggestions', 'yes' );
+	}
+
 	/**
 	 * Enqueue the Orders-screen promo card script and localize the resolved promo.
 	 *
@@ -479,12 +488,7 @@ class WC_Admin_Marketplace_Promotions {
 	 * @return array
 	 */
 	private static function fetch_marketplace_promotions() {
-		/**
-		 * Filter to suppress the requests for and showing of marketplace promotions.
-		 *
-		 * @since 8.8
-		 */
-		if ( apply_filters( 'woocommerce_marketplace_suppress_promotions', false ) ) {
+		if ( self::are_promotions_suppressed() ) {
 			return array();
 		}

@@ -537,18 +541,13 @@ class WC_Admin_Marketplace_Promotions {
 	 * add a filter to show a bubble on the Extensions item in the
 	 * WooCommerce menu.
 	 *
-	 * Use `woocommerce_marketplace_suppress_promotions` filter to suppress the bubble.
+	 * Skipped when promotions are suppressed (see `are_promotions_suppressed()`).
 	 *
 	 * @return void
 	 * @throws Exception  If we are unable to create a DateTime from the date_to_gmt.
 	 */
 	private static function maybe_show_bubble_promotions() {
-		/**
-		 * Filter to suppress the requests for and showing of marketplace promotions.
-		 *
-		 * @since 8.8
-		 */
-		if ( apply_filters( 'woocommerce_marketplace_suppress_promotions', false ) ) {
+		if ( self::are_promotions_suppressed() ) {
 			return;
 		}

diff --git a/plugins/woocommerce/includes/admin/settings/class-wc-settings-advanced.php b/plugins/woocommerce/includes/admin/settings/class-wc-settings-advanced.php
index 1466eed6935..ca6fbf511f3 100644
--- a/plugins/woocommerce/includes/admin/settings/class-wc-settings-advanced.php
+++ b/plugins/woocommerce/includes/admin/settings/class-wc-settings-advanced.php
@@ -493,7 +493,7 @@ class WC_Settings_Advanced extends WC_Settings_Page {
 				array(
 					'title'         => __( 'Show Suggestions', 'woocommerce' ),
 					'desc'          => __( 'Display suggestions within WooCommerce', 'woocommerce' ),
-					'desc_tip'      => esc_html__( 'Leave this box unchecked if you do not want to pull suggested extensions from WooCommerce.com.', 'woocommerce' ),
+					'desc_tip'      => esc_html__( 'Leave this box unchecked if you do not want to pull suggested extensions from WooCommerce.com. Payment provider offers on the Payments settings page are not affected by this setting.', 'woocommerce' ),
 					'id'            => 'woocommerce_show_marketplace_suggestions',
 					'abilities'     => array(
 						'read'  => true,
diff --git a/plugins/woocommerce/src/Internal/Admin/Events.php b/plugins/woocommerce/src/Internal/Admin/Events.php
index a209f56eaa3..de816f0dd44 100644
--- a/plugins/woocommerce/src/Internal/Admin/Events.php
+++ b/plugins/woocommerce/src/Internal/Admin/Events.php
@@ -253,8 +253,14 @@ class Events {
 	 *   when their related transients are missing or expired:
 	 *   - PaymentGatewaySuggestionsDataSourcePoller
 	 *   - RemoteFreeExtensionsDataSourcePoller
+	 *
+	 *   Skipped when marketplace suggestions are turned off: the readers of these specs use local defaults then.
 	 */
 	protected function possibly_refresh_data_source_pollers() {
+		if ( 'no' === get_option( 'woocommerce_show_marketplace_suggestions', 'yes' ) ) {
+			return;
+		}
+
 		$completed_tasks = get_option( 'woocommerce_task_list_tracked_completed_tasks', array() );

 		if ( ! in_array( 'payments', $completed_tasks, true ) && ! in_array( 'woocommerce-payments', $completed_tasks, true ) ) {
diff --git a/plugins/woocommerce/tests/e2e/tests/api-tests/settings/settings-crud.test.ts b/plugins/woocommerce/tests/e2e/tests/api-tests/settings/settings-crud.test.ts
index 942ce9a6237..8ae31e3bd0a 100644
--- a/plugins/woocommerce/tests/e2e/tests/api-tests/settings/settings-crud.test.ts
+++ b/plugins/woocommerce/tests/e2e/tests/api-tests/settings/settings-crud.test.ts
@@ -1803,7 +1803,7 @@ test.describe( 'Settings API tests: CRUD', () => {
 								'Display suggestions within WooCommerce',
 							type: 'checkbox',
 							default: 'yes',
-							tip: 'Leave this box unchecked if you do not want to pull suggested extensions from WooCommerce.com.',
+							tip: 'Leave this box unchecked if you do not want to pull suggested extensions from WooCommerce.com. Payment provider offers on the Payments settings page are not affected by this setting.',
 							value: expect.any( String ),
 						} ),
 					] )
diff --git a/plugins/woocommerce/tests/php/includes/admin/class-wc-admin-marketplace-promotions-test.php b/plugins/woocommerce/tests/php/includes/admin/class-wc-admin-marketplace-promotions-test.php
index 5d1395da6ed..73409306633 100644
--- a/plugins/woocommerce/tests/php/includes/admin/class-wc-admin-marketplace-promotions-test.php
+++ b/plugins/woocommerce/tests/php/includes/admin/class-wc-admin-marketplace-promotions-test.php
@@ -32,10 +32,31 @@ class WC_Admin_Marketplace_Promotions_Test extends WC_Unit_Test_Case {
 		'woocommerce-product-addon',
 	);

+	/**
+	 * The promotions locale before the test, or null if it was not set yet.
+	 *
+	 * @var string|null
+	 */
+	private ?string $original_promotions_locale = null;
+
+	/**
+	 * Remember the promotions locale so tearDown can restore it.
+	 */
+	public function setUp(): void {
+		parent::setUp();
+
+		$locale                           = new ReflectionProperty( WC_Admin_Marketplace_Promotions::class, 'locale' );
+		$this->original_promotions_locale = $locale->isInitialized() ? WC_Admin_Marketplace_Promotions::$locale : null;
+	}
+
 	/**
 	 * Clean up state between tests.
 	 */
 	public function tearDown(): void {
+		// A typed static cannot go back to uninitialized, so only a value that was set before can be restored.
+		if ( null !== $this->original_promotions_locale ) {
+			WC_Admin_Marketplace_Promotions::$locale = $this->original_promotions_locale;
+		}
 		delete_transient( WC_Admin_Marketplace_Promotions::TRANSIENT_NAME );
 		delete_option( 'woocommerce_allow_tracking' );
 		$this->reset_orders_promo_cache();
@@ -57,6 +78,88 @@ class WC_Admin_Marketplace_Promotions_Test extends WC_Unit_Test_Case {
 		$card->setValue( null, null );
 	}

+	/**
+	 * @testdox The scheduled promotions update only calls WooCommerce.com when marketplace suggestions are on and promotions are not suppressed.
+	 * @testWith ["yes", false, 1]
+	 *           ["no", false, 0]
+	 *           [null, false, 1]
+	 *           ["yes", true, 0]
+	 *
+	 * @param string|null $setting           Marketplace suggestions setting, or null to leave it unset.
+	 * @param bool        $suppressed        Whether the suppression filter returns true.
+	 * @param int         $expected_requests Expected number of requests to the promotions API.
+	 */
+	public function test_update_promotions_respects_marketplace_suggestions_setting( ?string $setting, bool $suppressed, int $expected_requests ): void {
+		delete_option( 'woocommerce_show_marketplace_suggestions' );
+		if ( null !== $setting ) {
+			update_option( 'woocommerce_show_marketplace_suggestions', $setting );
+		}
+		add_filter( 'woocommerce_marketplace_suppress_promotions', $suppressed ? '__return_true' : '__return_false' );
+		set_transient( WC_Admin_Marketplace_Promotions::TRANSIENT_NAME, array( array( 'id' => 'stale' ) ) );
+
+		$this->http_responder = static fn() => array(
+			'response' => array( 'code' => 200 ),
+			'body'     => '[]',
+		);
+
+		$suppress_filter_runs = did_filter( 'woocommerce_marketplace_suppress_promotions' );
+
+		WC_Admin_Marketplace_Promotions::update_promotions();
+
+		$this->assertSame( $suppress_filter_runs + 1, did_filter( 'woocommerce_marketplace_suppress_promotions' ), 'The suppression filter should still run, whatever the setting.' );
+		$requests = array_filter( $this->http_requests, static fn( $request ) => str_starts_with( $request['url'], WC_Admin_Marketplace_Promotions::PROMOTIONS_API_URL ) );
+		$this->assertCount( $expected_requests, $requests, 'Promotions should be requested only when marketplace suggestions are on.' );
+		$this->assertSame( array(), get_transient( WC_Admin_Marketplace_Promotions::TRANSIENT_NAME ), 'Cached promotions should be replaced with an empty list.' );
+	}
+
+	/**
+	 * @testdox Cached promotions and the Extensions menu badge are hidden as soon as marketplace suggestions are turned off or promotions are suppressed.
+	 * @testWith ["yes", false, true]
+	 *           ["no", false, false]
+	 *           ["yes", true, false]
+	 *
+	 * @param string $setting        Marketplace suggestions setting.
+	 * @param bool   $suppressed     Whether the suppression filter returns true.
+	 * @param bool   $expect_visible Whether the cached promotions should be shown.
+	 */
+	public function test_cached_promotions_respect_marketplace_suggestions_setting( string $setting, bool $suppressed, bool $expect_visible ): void {
+		update_option( 'woocommerce_show_marketplace_suggestions', $setting );
+		add_filter( 'woocommerce_marketplace_suppress_promotions', $suppressed ? '__return_true' : '__return_false' );
+		set_transient(
+			WC_Admin_Marketplace_Promotions::TRANSIENT_NAME,
+			array(
+				array(
+					'id'            => 'extensions-sale',
+					'date_from_gmt' => '2025-01-01 00:00:00',
+					'date_to_gmt'   => '2099-01-01 00:00:00',
+					'format'        => 'menu_bubble',
+					'menu_item_id'  => 'woocommerce-marketplace',
+					'content'       => array( 'en_US' => 'Sale' ),
+				),
+			)
+		);
+
+		// init() sets the locale on admin requests; tests never run it.
+		WC_Admin_Marketplace_Promotions::$locale = 'en_US';
+
+		$show_bubble = new ReflectionMethod( WC_Admin_Marketplace_Promotions::class, 'maybe_show_bubble_promotions' );
+		$show_bubble->setAccessible( true );
+		$show_bubble->invoke( null );
+		$menu_items = apply_filters(
+			'woocommerce_marketplace_menu_items',
+			array(
+				array(
+					'id'     => 'woocommerce-marketplace',
+					'parent' => 'woocommerce',
+					'title'  => 'Extensions',
+				),
+			)
+		);
+
+		$this->assertCount( $expect_visible ? 1 : 0, WC_Admin_Marketplace_Promotions::get_active_promotions(), 'Active promotions should follow the marketplace suggestions setting.' );
+		$this->assertSame( $expect_visible, str_contains( $menu_items[0]['title'], 'Sale' ), 'The Extensions menu badge should follow the marketplace suggestions setting.' );
+	}
+
 	/**
 	 * Build the "none of these add-on plugins active" exclusion rule.
 	 *
diff --git a/plugins/woocommerce/tests/php/src/Internal/Admin/EventsTest.php b/plugins/woocommerce/tests/php/src/Internal/Admin/EventsTest.php
new file mode 100644
index 00000000000..4619a628313
--- /dev/null
+++ b/plugins/woocommerce/tests/php/src/Internal/Admin/EventsTest.php
@@ -0,0 +1,56 @@
+<?php
+declare( strict_types = 1 );
+
+namespace Automattic\WooCommerce\Tests\Internal\Admin;
+
+use Automattic\WooCommerce\Admin\Features\PaymentGatewaySuggestions\PaymentGatewaySuggestionsDataSourcePoller;
+use Automattic\WooCommerce\Internal\Admin\Events;
+use Automattic\WooCommerce\Internal\Admin\RemoteFreeExtensions\RemoteFreeExtensionsDataSourcePoller;
+use WC_Unit_Test_Case;
+
+/**
+ * Tests for the Events class.
+ */
+class EventsTest extends WC_Unit_Test_Case {
+
+	/**
+	 * @testdox The daily refresh only downloads payment gateway and free extension suggestions when marketplace suggestions are on.
+	 * @testWith ["yes", 1]
+	 *           ["no", 0]
+	 *           [null, 1]
+	 *
+	 * @param string|null $setting           Marketplace suggestions setting, or null to leave it unset.
+	 * @param int         $expected_requests Expected requests for each of the two suggestion lists.
+	 */
+	public function test_data_source_pollers_refresh_respects_marketplace_suggestions_setting( ?string $setting, int $expected_requests ): void {
+		delete_option( 'woocommerce_show_marketplace_suggestions' );
+		if ( null !== $setting ) {
+			update_option( 'woocommerce_show_marketplace_suggestions', $setting );
+		}
+		update_option( 'woocommerce_task_list_tracked_completed_tasks', array() );
+		PaymentGatewaySuggestionsDataSourcePoller::get_instance()->delete_specs_transient();
+		RemoteFreeExtensionsDataSourcePoller::get_instance()->delete_specs_transient();
+
+		$this->http_responder = static fn() => array(
+			'response' => array( 'code' => 200 ),
+			'body'     => '[]',
+		);
+
+		$refresh = new \ReflectionMethod( Events::class, 'possibly_refresh_data_source_pollers' );
+		$refresh->setAccessible( true );
+		$refresh->invoke( Events::instance() );
+
+		$this->assertCount( $expected_requests, $this->requests_to( '/payment-gateway-suggestions/' ), 'Payment gateway suggestions should be downloaded only when marketplace suggestions are on.' );
+		$this->assertCount( $expected_requests, $this->requests_to( '/obw-free-extensions/' ), 'Free extension suggestions should be downloaded only when marketplace suggestions are on.' );
+	}
+
+	/**
+	 * Recorded HTTP requests whose URL contains the given path.
+	 *
+	 * @param string $path URL fragment to match.
+	 * @return array
+	 */
+	private function requests_to( string $path ): array {
+		return array_filter( $this->http_requests, static fn( $request ) => str_contains( $request['url'], $path ) );
+	}
+}