Skip to content

Sync: Build WooCommerce Analytics order stats from WooCommerce's own row - #55530

Draft
chihsuan wants to merge 2 commits into
trunkfrom
update/wooa7s-2265-sync-use-core-order-stats-row
Draft

chihsuan wants to merge 2 commits into
trunkfrom
update/wooa7s-2265-sync-use-core-order-stats-row

Conversation

@chihsuan

@chihsuan chihsuan commented Nov 27, 2026 •

Copy link
Copy Markdown
Member

Part of WOOA7S-2265

Proposed changes

  • When WooCommerce provides Orders\Stats\DataStore::get_order_stats_row_data() (Expose the order stats row calculation as a public method woocommerce/woocommerce#69399), the WooCommerce Analytics module builds the order_stats payload from WooCommerce's own row and adds the hosted-only fee and discount columns on top. Older WooCommerce versions keep the current code.
  • Plugins that change the row through woocommerce_analytics_update_order_stats_data now change the synced row too.
  • Statuses get the same wc- prefix as WooCommerce's row, including unregistered statuses.
  • Refund rows take their status from the stored wc_order_stats row, so the checksum matches with or without the standalone WooCommerce Analytics plugin.
  • The payload also carries date_created_gmt and payment_method, which the deleted-order path already sends.
  • When WooCommerce no longer tracks an order that already has a stored row, such as a test order imported earlier, the module sends that stored row.

Resending refunds when their parent changes and the FulfillmentUtils namespace on WooCommerce 11.0+ are not covered here. With the opt-in immediate sync in #53176, refunds synced before their row is stored and orders trashed before import still need a decision there.

Related product discussion/links

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

No. It sends the same actions, plus two columns the deleted-order path already sends.

Testing instructions

Setup: a connected site with WooCommerce built from woocommerce/woocommerce#69399, Premium Analytics (or Jetpack) built from this branch, and Analytics enabled. Do not activate the standalone WooCommerce Analytics plugin. Add an mu-plugin that logs the payload:

add_action( 'woocommerce_analytics_sync_reports_data', function ( $data ) {
	error_log( 'WCA sync ' . wp_json_encode( $data['order_stats'] ) );
}, 1 );

Refund status

  1. Place an order, set it to Processing, then refund one line item. Run wp action-scheduler run --group=wc-admin-data.
  2. Confirm the logged refund row's status is wc-processing, the same as SELECT status FROM wp_wc_order_stats WHERE order_id = <refund id>. On trunk it logs wc-completed.

Filter

  1. Add add_filter( 'woocommerce_analytics_update_order_stats_data', function ( $d ) { $d['num_items_sold'] = 99; return $d; } ); to the mu-plugin.
  2. Save an order and run the imports. Confirm the logged num_items_sold is 99.

Order WooCommerce no longer tracks

  1. Place an order, set it to Processing, and run the imports.
  2. Add the _wcpay_mode meta with the value test to the order (for example $order->update_meta_data( '_wcpay_mode', 'test' ); $order->save_meta_data(); in wp shell), then call get_object_by_id( 'order', <id> ) on the module.
  3. Confirm the payload still has order_stats, matching the stored row.

Older WooCommerce

  1. Switch WooCommerce to trunk without #69399 and repeat the refund steps.
  2. Confirm the payload matches trunk Jetpack: the refund keeps wc-completed, and there is no date_created_gmt key.

@github-actions

github-actions Bot commented Nov 27, 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 or WordPress.com Site Helper), and enable the update/wooa7s-2265-sync-use-core-order-stats-row branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack update/wooa7s-2265-sync-use-core-order-stats-row
bin/jetpack-downloader test jetpack-mu-wpcom-plugin update/wooa7s-2265-sync-use-core-order-stats-row

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

@github-actions

github-actions Bot commented Nov 27, 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.

@github-actions github-actions Bot added the [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. label Nov 27, 2026
@jp-launch-control

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

Copy link
Copy Markdown

Code Coverage Summary

Coverage changed in 1 file.

File Coverage Δ% Δ Uncovered
projects/packages/sync/src/modules/class-woocommerce-analytics.php 190/568 (33.45%) -2.33% 37 💔

Full summary · PHP report · JS report

Coverage check overridden by I don't care about code coverage for this PR Use this label to ignore the check for insufficient code coveage. .

@github-actions github-actions Bot added [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Tests] Includes Tests labels Nov 27, 2026
@chihsuan chihsuan added the I don't care about code coverage for this PR Use this label to ignore the check for insufficient code coveage. label Nov 27, 2026

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

I don't care about code coverage for this PR Use this label to ignore the check for insufficient code coveage. [Package] Sync [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Status] In Progress [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. [Tests] Includes Tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant