Skip to content

WooCommerce Stats: Hide the WooCommerce tab on self-hosted stores - #55436

Open
retrofox wants to merge 6 commits into
trunkfrom
wooa7s-2539-hide-the-woocommerce-stats-tab-on-self-hosted
Open

retrofox wants to merge 6 commits into
trunkfrom
wooa7s-2539-hide-the-woocommerce-stats-tab-on-self-hosted

Conversation

@retrofox

@retrofox retrofox commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Fixes WOOA7S-2539

Proposed changes

A feature flag turns WooCommerce Stats on

The WooCommerce Stats package registers jetpack-woocommerce-stats, off by default. Analytics_Dashboard::is_enabled() reads it.

While it is off, nobody may read store reports: the gate sits in current_user_can_view_store_reports(). So the WooCommerce tab, its widget types, the Bookings metric and the reports proxy go away together. The store currency is left out of the script data too.

The store reports Premium Analytics still serves

While the flag is off, the package also refuses the analytics group of the Premium Analytics proxy and its CSV export. Premium Analytics itself does not change.

WordPress.com keeps the tab

wpcomsh turns the flag on in #55498. That one has to be deployed to Atomic before this PR is merged.

Not here

Sync_Configuration and WooCommerce_Analytics_Tracker are untouched. Tracking is WOOA7S-2538, which can read Analytics_Dashboard::is_enabled().

The package now requires automattic/jetpack-feature-flags, hence the three plugin lock files.

Related product discussion/links

Does this pull request change what data or activity we track or use?

No. Front-end store tracking changes are tracked separately in WOOA7S-2538.

Testing instructions

Self-hosted store: hidden

Use a self-hosted site (Jurassic Ninja or local Docker) with Jetpack, Stats v2 on and WooCommerce active. Open Jetpack → Stats as an administrator.

The WooCommerce tab is not there, the dashboard opens on Traffic, and the inserter offers no WooCommerce widgets.

trunk this PR
Screenshot 2026-11-25 at 4 04 34 PM Screenshot 2026-11-25 at 4 02 34 PM

wp-admin/admin.php?page=jetpack-premium-analytics-wp-admin&section=woocommerce falls back to the first available tab.

A Shop Manager without view_stats cannot open the Stats dashboard.

The reports answer 403

Both of these answer 403:

GET /wp-json/jetpack/v4/woocommerce-stats/proxy/v2/analytics/reports/orders/by-date
GET /wp-json/jetpack-premium-analytics/v1/proxy/v2/analytics/reports/orders/by-date

Flag on: everything is back

On Jurassic Ninja:

wp companion feature-flag enable jetpack-woocommerce-stats

Anywhere else, in a mu-plugin:

add_filter( 'jetpack_feature_flag_enabled_jetpack-woocommerce-stats', '__return_true' );

Reload Jetpack → Stats: the WooCommerce tab, its widgets, the currency formatting and the reports work as before.

Atomic

With this branch alone the tab is gone on Atomic, until #55498 is there.

Automated tests

jp test php packages/woocommerce-stats
jp phan packages/woocommerce-stats

Co-authored-by: Cursor <cursoragent@cursor.com>
@retrofox retrofox added Enhancement Changes to an existing feature — removing, adding, or changing parts of it [Status] Needs Review This PR is ready for review. labels Nov 25, 2026
@retrofox retrofox self-assigned this Nov 25, 2026
@github-actions

github-actions Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • ✅ Add a "[Status]" label (In Progress, Needs Review, ...).
  • ✅ Add testing instructions.
  • ✅ Specify whether this PR includes any changes to data or privacy.
  • ✅ Add changelog entries to affected projects

This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖


Follow this PR Review Process:

  1. Ensure all required checks appearing at the bottom of this PR are passing.
  2. Make sure to test your changes on all platforms that it applies to. You're responsible for the quality of the code you ship.
  3. You can use GitHub's Reviewers functionality to request a review.
  4. When it's reviewed and merged, you will be pinged in Slack to deploy the changes to WordPress.com simple once the build is done.

If you have questions about anything, reach out in #jetpack-developers for guidance!


Jetpack plugin:

The Jetpack plugin has different release cadences depending on the platform:

  • WordPress.com Simple releases happen as soon as you deploy your changes after merging this PR (PCYsg-Jjm-p2).
  • WoA releases happen weekly.
  • Releases to self-hosted sites happen monthly:
    • Scheduled release: December 8, 2026
    • Code freeze: December 7, 2026

If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack.


Premium Analytics plugin:

No scheduled milestone found for this plugin.

If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack.


Stats Data plugin:

No scheduled milestone found for this plugin.

If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack.

…-woocommerce-stats-tab-on-self-hosted

Co-authored-by: Cursor <cursoragent@cursor.com>

# Conflicts:
#	projects/packages/woocommerce-stats/src/class-analytics-dashboard.php
#	projects/packages/woocommerce-stats/tests/php/Analytics_Dashboard_Test.php
@github-actions

github-actions Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.

  • To test on WoA, go to the Plugins menu on a WoA dev site. Click on the "Upload" button and follow the upgrade flow to be able to upload, install, and activate the Jetpack Beta plugin. Once the plugin is active, go to Jetpack > Jetpack Beta, select your plugin (Jetpack), and enable the wooa7s-2539-hide-the-woocommerce-stats-tab-on-self-hosted branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack wooa7s-2539-hide-the-woocommerce-stats-tab-on-self-hosted

Interested in more tips and information?

  • In your local development environment, use the jetpack rsync command to sync your changes to a WoA dev blog.
  • Read more about our development workflow here: PCYsg-eg0-p2
  • Figure out when your changes will be shipped to customers here: PCYsg-eg5-p2

@jp-launch-control

jp-launch-control Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Code Coverage Summary

Coverage changed in 2 files.

File Coverage Δ% Δ Uncovered
projects/packages/woocommerce-stats/src/class-analytics-dashboard.php 179/188 (95.21%) 0.24% 0 💚
projects/packages/woocommerce-stats/src/class-api-proxy-controller.php 124/128 (96.88%) 0.35% 0 💚

Full summary · PHP report · JS report

@chihsuan chihsuan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @retrofox! Since this gate is temporary until history limits and billing ship, would it make sense to use a feature flag that's off by default and turned on from wpcomsh? That keeps host checks out of the package, like classic Stats retirement. Left a couple of inline notes too.

*/
public function check_permission() {
return Analytics_Dashboard::current_user_can_view_store_reports();
return Analytics_Dashboard::is_enabled() && Analytics_Dashboard::current_user_can_view_store_reports();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the 403 meant to block the report data, or mainly to back up hiding the tab? I noticed the same request still returns 200 through the Premium Analytics proxy, which CSV export also uses. That includes a shop manager who can no longer open the dashboard.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is meant to block the data, not only to back up the hidden tab. Good catch on the Premium Analytics proxy.

The gate moved into the store reports rule, current_user_can_view_store_reports(), so the tab, the widgets, and this proxy all follow it.
And while the flag is off, the package now refuses the two routes Premium Analytics still serves: the analytics group of its proxy and the CSV export.

It reads endpoint the way that proxy does, so a query-string endpoint cannot get around it. A shop manager gets a 403 on both.

I did it from this package on purpose, so Premium Analytics learns nothing new about WooCommerce. It goes away once the CSV export moves here 🤞

It is still the plugin refusing its own routes. A limit on the data itself has to live on the WordPress.com side.

#[PreserveGlobalState( false )]
public function test_script_data_adds_the_store_currency_beside_existing_keys() {
require_once __DIR__ . '/mocks/woocommerce-mock.php';
add_filter( Analytics_Dashboard::ENABLED_FILTER, '__return_true' );

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should test_script_data_is_unchanged_without_woocommerce turn the gate on too? Right now it never reaches the WooCommerce checks.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, good catch again :-)

It turns the flag on now and runs in its own process, so it gets to the WooCommerce checks.

replaces the host check and its filter; the gate sits in the store reports rule
refuses the dashboard proxy's analytics group and its csv export while the flag is off
louwie17
louwie17 previously approved these changes Nov 26, 2026

@louwie17 louwie17 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @retrofox, this tested well on a local Docker site and @chihsuan's points look addressed. The main thing is merge order, should we merge #55498 first before we merge this one? ( left an inline comment ) The description also still mentions the Host check and the old filter, worth a quick update.

Co-reviewed and tested with Claude and Codex.

Feature_Flags::register(
self::FLAG,
array(
'default' => false,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we merge #55498 first before we merge this one? It looks independent of these changes, and would avoid an accidental late merge that leaves Atomic sites without their Woo tab.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, #55498 goes first. It does nothing until this one lands, and wpcomsh reaches Atomic twice a day, so I will merge this only after checking it is live there. Marked this PR as blocked until then, and updated the description.

public static function data_dashboard_store_routes() {
return array(
'the analytics group of the proxy' => array( 'GET', '/jetpack-premium-analytics/v1/proxy/v2/analytics/reports/orders/by-date', array() ),
'a route in another letter case' => array( 'GET', '/Jetpack-Premium-Analytics/v1/Proxy/v2/analytics/reports/orders/by-date', array() ),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small nit, maybe capitalize Analytics too, so this row covers the strtolower() on endpoint.

Suggested change
'a route in another letter case' => array( 'GET', '/Jetpack-Premium-Analytics/v1/Proxy/v2/analytics/reports/orders/by-date', array() ),
'a route in another letter case' => array( 'GET', '/Jetpack-Premium-Analytics/v1/Proxy/v2/Analytics/reports/orders/by-date', array() ),

the mixed-case row now fails if the group is not lowercased
…-woocommerce-stats-tab-on-self-hosted

# Conflicts:
#	projects/plugins/jetpack/composer.lock
#	projects/plugins/premium-analytics/composer.lock
#	projects/plugins/stats/composer.lock
@chihsuan

Copy link
Copy Markdown
Member

I merged trunk into this branch to unblock #55483. Only the composer.lock references conflicted, and I regenerated them.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Docs Enhancement Changes to an existing feature — removing, adding, or changing parts of it [Package] Woocommerce Stats [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Plugin] Premium Analytics [Plugin] Stats Data [Status] Blocked / Hold [Status] Needs Review This PR is ready for review. [Tests] Includes Tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants