Commit 3fe515b8d6b for woocommerce

commit 3fe515b8d6b85edefb7855e1786cbf3c5a7ddba5
Author: Vladimir Reznichenko <kalessil@gmail.com>
Date:   Tue Sep 15 11:33:35 2026 +0200

    [Fix] Flush product count cache on plugin (de)activation so custom product statuses appear immediately (#68723)

    Adopts the fix from #68114 and applies it to persistent product counters infrastructure.

diff --git a/plugins/woocommerce/changelog/flush-product-count-cache-on-plugin-activation b/plugins/woocommerce/changelog/flush-product-count-cache-on-plugin-activation
new file mode 100644
index 00000000000..46407e85707
--- /dev/null
+++ b/plugins/woocommerce/changelog/flush-product-count-cache-on-plugin-activation
@@ -0,0 +1,4 @@
+Significance: patch
+Type: fix
+
+Flush product count cache on plugin (de)activation so custom product statuses appear immediately.
diff --git a/plugins/woocommerce/src/Caches/ProductCountCacheService.php b/plugins/woocommerce/src/Caches/ProductCountCacheService.php
index 0ba24083660..76ab5927483 100644
--- a/plugins/woocommerce/src/Caches/ProductCountCacheService.php
+++ b/plugins/woocommerce/src/Caches/ProductCountCacheService.php
@@ -57,6 +57,8 @@ class ProductCountCacheService {

 		add_action( 'action_scheduler_ensure_recurring_actions', array( $this, 'schedule_background_actions' ) );
 		add_action( self::BACKGROUND_EVENT_HOOK, array( $this, 'prime_cache_if_cold' ) );
+		add_action( 'activated_plugin', array( $this, 'flush_cache' ) );
+		add_action( 'deactivated_plugin', array( $this, 'flush_cache' ) );
 		if ( defined( 'WC_PLUGIN_BASENAME' ) ) {
 			add_action( 'deactivate_' . WC_PLUGIN_BASENAME, array( $this, 'unschedule_background_actions' ) );
 		}
@@ -81,6 +83,18 @@ class ProductCountCacheService {
 		}
 	}

+	/**
+	 * Flushes the product count cache.
+	 *
+	 * @internal
+	 * @since 11.2.0
+	 *
+	 * @return void
+	 */
+	public function flush_cache(): void {
+		$this->product_count_cache->flush( 'product' );
+	}
+
 	/**
 	 * Register background caching for each product type.
 	 *
diff --git a/plugins/woocommerce/tests/php/src/Caching/ProductCountCacheServiceTest.php b/plugins/woocommerce/tests/php/src/Caching/ProductCountCacheServiceTest.php
index 85aeb04d176..541fe437021 100644
--- a/plugins/woocommerce/tests/php/src/Caching/ProductCountCacheServiceTest.php
+++ b/plugins/woocommerce/tests/php/src/Caching/ProductCountCacheServiceTest.php
@@ -336,4 +336,28 @@ final class ProductCountCacheServiceTest extends \WC_Unit_Test_Case {

 		$this->assertNull( $this->product_cache->get( 'product', array( ProductStatus::PUBLISH ) ) );
 	}
+
+	/**
+	 * @testdox Cache is flushed when a plugin is activated.
+	 */
+	public function test_activated_plugin_flushes_cache(): void {
+		$this->product_util->get_counts_for_type( 'product' );
+		$this->assertNotNull( $this->product_cache->get( 'product' ) );
+
+		do_action( 'activated_plugin', 'some-plugin/some-plugin.php', false );
+
+		$this->assertNull( $this->product_cache->get( 'product' ) );
+	}
+
+	/**
+	 * @testdox Cache is flushed when a plugin is deactivated.
+	 */
+	public function test_deactivated_plugin_flushes_cache(): void {
+		$this->product_util->get_counts_for_type( 'product' );
+		$this->assertNotNull( $this->product_cache->get( 'product' ) );
+
+		do_action( 'deactivated_plugin', 'some-plugin/some-plugin.php', false );
+
+		$this->assertNull( $this->product_cache->get( 'product' ) );
+	}
 }