Commit ea399ae01c8 for woocommerce

commit ea399ae01c893f25c85b8ab6c901f7f163ccde4c
Author: Luigi Teschio <gigitux@gmail.com>
Date:   Thu Jul 9 13:14:04 2026 +0200

    Fix analytics legacy admin disable filters (#66444)

    * Fix analytics legacy admin disable filters

    * Add changelog for analytics legacy filter fix

    * fix logic

    * fix lint code

diff --git a/plugins/woocommerce/changelog/fix-analytics-legacy-admin-disable-filters b/plugins/woocommerce/changelog/fix-analytics-legacy-admin-disable-filters
new file mode 100644
index 00000000000..e451c64e87a
--- /dev/null
+++ b/plugins/woocommerce/changelog/fix-analytics-legacy-admin-disable-filters
@@ -0,0 +1,4 @@
+Significance: patch
+Type: fix
+
+Respect legacy WooCommerce Admin filters when disabling analytics.
diff --git a/plugins/woocommerce/src/Admin/Features/Features.php b/plugins/woocommerce/src/Admin/Features/Features.php
index ae534c8ae8e..9fcd94314a6 100644
--- a/plugins/woocommerce/src/Admin/Features/Features.php
+++ b/plugins/woocommerce/src/Admin/Features/Features.php
@@ -531,6 +531,24 @@ class Features {
 		return apply_filters( 'woocommerce_admin_features', array_keys( self::get_legacy_feature_compatibility_defaults() ) );
 	}

+	/**
+	 * Checks if Analytics was disabled by legacy WooCommerce Admin filters.
+	 *
+	 * @return bool True if Analytics was disabled by legacy filters.
+	 */
+	public static function is_analytics_disabled_by_legacy_filters(): bool {
+		/**
+		 * Filter allowing WooCommerce Admin optional features to be disabled.
+		 *
+		 * @param bool $disabled False.
+		 */
+		if ( apply_filters( 'woocommerce_admin_disabled', false ) ) { // phpcs:ignore WooCommerce.Commenting.CommentHooks.MissingSinceComment
+			return true;
+		}
+
+		return ! in_array( 'analytics', self::get_features_with_legacy_compatibility_defaults(), true );
+	}
+
 	/**
 	 * Checks if a feature slug is supported only by the legacy compatibility shim.
 	 *
diff --git a/plugins/woocommerce/src/Internal/Features/FeaturesController.php b/plugins/woocommerce/src/Internal/Features/FeaturesController.php
index 76d59c3b1dd..dbd567e205a 100644
--- a/plugins/woocommerce/src/Internal/Features/FeaturesController.php
+++ b/plugins/woocommerce/src/Internal/Features/FeaturesController.php
@@ -11,6 +11,7 @@ use Automattic\WooCommerce\Internal\Admin\EmailPreview\EmailPreview;
 use WC_Tracks;
 use WC_Site_Tracking;
 use Automattic\Jetpack\Constants;
+use Automattic\WooCommerce\Admin\Features\Features as WCAdminFeatures;
 use Automattic\WooCommerce\Internal\Admin\Analytics;
 use Automattic\WooCommerce\Internal\Caches\ProductCacheController;
 use Automattic\WooCommerce\Internal\DataStores\Orders\CustomOrdersTableController;
@@ -935,6 +936,10 @@ class FeaturesController {
 			return (bool) ( $feature['deprecated_value'] ?? false );
 		}

+		if ( 'analytics' === $feature_id && WCAdminFeatures::is_analytics_disabled_by_legacy_filters() ) {
+			return false;
+		}
+
 		if ( $this->is_preview_email_improvements_enabled( $feature_id ) ) {
 			return true;
 		}
diff --git a/plugins/woocommerce/tests/php/src/Admin/Features/Analytics/FeatureEnabledTest.php b/plugins/woocommerce/tests/php/src/Admin/Features/Analytics/FeatureEnabledTest.php
index 8ea53266947..b8cab2e9b8c 100644
--- a/plugins/woocommerce/tests/php/src/Admin/Features/Analytics/FeatureEnabledTest.php
+++ b/plugins/woocommerce/tests/php/src/Admin/Features/Analytics/FeatureEnabledTest.php
@@ -19,6 +19,8 @@ class FeatureEnabledTest extends WC_Unit_Test_Case {
 		delete_option( 'woocommerce_analytics_enabled' );
 		delete_option( RemoteInboxNotifications::TOGGLE_OPTION_NAME );
 		remove_filter( 'woocommerce_admin_features', array( $this, 'enable_analytics_feature' ) );
+		remove_filter( 'woocommerce_admin_features', array( $this, 'disable_analytics_feature' ), PHP_INT_MAX );
+		remove_filter( 'woocommerce_admin_disabled', '__return_true', PHP_INT_MAX );
 		remove_filter( 'woocommerce_admin_features', array( $this, 'disable_launch_your_store_feature' ) );
 		remove_filter( 'woocommerce_admin_features', array( $this, 'disable_customize_store_feature' ) );

@@ -37,6 +39,38 @@ class FeatureEnabledTest extends WC_Unit_Test_Case {
 		);
 	}

+	/**
+	 * @testdox Should disable analytics when removed from the legacy admin feature list.
+	 */
+	public function test_should_be_disabled_when_removed_from_legacy_admin_features(): void {
+		add_filter( 'woocommerce_admin_features', array( $this, 'disable_analytics_feature' ), PHP_INT_MAX );
+
+		try {
+			$this->assertFalse(
+				FeaturesUtil::feature_is_enabled( 'analytics' ),
+				'Analytics should be disabled when removed from the legacy admin feature list.'
+			);
+		} finally {
+			remove_filter( 'woocommerce_admin_features', array( $this, 'disable_analytics_feature' ), PHP_INT_MAX );
+		}
+	}
+
+	/**
+	 * @testdox Should disable analytics when WooCommerce Admin is disabled by legacy filter.
+	 */
+	public function test_should_be_disabled_when_woocommerce_admin_is_disabled(): void {
+		add_filter( 'woocommerce_admin_disabled', '__return_true', PHP_INT_MAX );
+
+		try {
+			$this->assertFalse(
+				FeaturesUtil::feature_is_enabled( 'analytics' ),
+				'Analytics should be disabled when WooCommerce Admin is disabled.'
+			);
+		} finally {
+			remove_filter( 'woocommerce_admin_disabled', '__return_true', PHP_INT_MAX );
+		}
+	}
+
 	/**
 	 * @testdox Should remove analytics from legacy admin features when the option value is disabled.
 	 */
@@ -153,6 +187,16 @@ class FeatureEnabledTest extends WC_Unit_Test_Case {
 		return array_unique( $features );
 	}

+	/**
+	 * Disable the analytics feature in the legacy admin feature list.
+	 *
+	 * @param array $features Feature slugs.
+	 * @return array
+	 */
+	public function disable_analytics_feature( array $features ): array {
+		return array_values( array_diff( $features, array( 'analytics' ) ) );
+	}
+
 	/**
 	 * Disable the launch your store feature in the legacy admin feature list.
 	 *