Skip to content

Sync: Fix WooCommerce Analytics refund rows going stale after their order is re-imported - #55533

Draft
chihsuan wants to merge 3 commits into
trunkfrom
fix/wooa7s-2265-sync-refunds-and-fulfillment-utils
Draft

chihsuan wants to merge 3 commits into
trunkfrom
fix/wooa7s-2265-sync-refunds-and-fulfillment-utils

Conversation

@chihsuan

@chihsuan chihsuan commented Nov 27, 2026 •

Copy link
Copy Markdown
Member

Part of WOOA7S-2265

Proposed changes

  • Resend an order's refunds when WooCommerce imports the order. That import also rewrites the refunds' wc_order_stats rows, but woocommerce_order_scheduler_after_import_order fires once, for the order, so hosted refund rows went stale when their order changed. A refund the import left without a row (excluded or deleted) is not resent.
  • Find FulfillmentUtils in either namespace. It moved to Admin\Features\Fulfillments in WooCommerce 10.7, so on stores without the fulfillment_status column the module sent null instead of the order's fulfillment status.

In scheduled imports, a refund imported in the same batch as its order is sent twice; the second copy carries the row the order's import rewrote.

Related product discussion/links

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

No. It sends the same actions and payload. A refund is sent once more when its order is imported.

Testing instructions

Setup: a connected site with WooCommerce 10.3 or later, Analytics enabled, and Premium Analytics (or Jetpack) built from this branch. Add an mu-plugin that logs each synced order ID:

add_action( 'woocommerce_analytics_sync_reports_data', function ( $data ) {
	error_log( 'WCA sync ' . $data['order_stats']['order_id'] . ' fulfillment=' . var_export( $data['order_stats']['fulfillment_status'], true ) );
}, 1 );

Refunds resent with their order

  1. Place an order, set it to Processing, refund one line item, and run wp action-scheduler run --group=wc-admin-data.
  2. Change the order's status to Completed and run the imports again. With Analytics > Settings > Updates set to Scheduled, run the pending wc-admin_process_pending_orders_batch action from WooCommerce > Status > Scheduled Actions instead.
  3. Confirm the log shows both the order and the refund for step 2. On trunk it shows only the order.
  4. Change the status of an order without refunds. Confirm only that order is logged.

Fulfillment status on WooCommerce 10.7 to 11.4

  1. On a test store running WooCommerce 10.7 to 11.4, drop the column with wp db query "ALTER TABLE wp_wc_order_stats DROP COLUMN fulfillment_status" and run wp option update woocommerce_order_stats_has_fulfillment_column no.
  2. Give an order a fulfillment status (for example the _fulfillment_status meta set to partially_fulfilled) and save it, then run the imports.
  3. Confirm the logged fulfillment is 'partially_fulfilled'. On trunk it is NULL.

@chihsuan chihsuan self-assigned this Nov 27, 2026
@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 fix/wooa7s-2265-sync-refunds-and-fulfillment-utils branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack fix/wooa7s-2265-sync-refunds-and-fulfillment-utils
bin/jetpack-downloader test jetpack-mu-wpcom-plugin fix/wooa7s-2265-sync-refunds-and-fulfillment-utils

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 added [Package] Sync [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Status] In Progress [Tests] Includes Tests labels Nov 27, 2026
@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/556 (34.17%) -1.61% 25 💔

Full summary · PHP report · JS report

Coverage check overridden by Covered by non-unit tests Use to ignore the Code coverage requirement check when E2Es or other non-unit tests cover the code .

@chihsuan chihsuan added the Covered by non-unit tests Use to ignore the Code coverage requirement check when E2Es or other non-unit tests cover the code 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

Covered by non-unit tests Use to ignore the Code coverage requirement check when E2Es or other non-unit tests cover the code [Package] Sync [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Plugin] Premium Analytics [Plugin] Stats Data [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