Skip to content

Conversation

@coder-karen
Copy link
Contributor

@coder-karen coder-karen commented Dec 1, 2025

Fixes SYNC-174

Proposed changes:

  • This PR prevents woocommerce_update_order_item from being synced multiple times per order, for orders with multiple items, when only one item is being updated.

What we are doing:

  • We are tracking real item changes per request with woocommerce_before_order_item_object_save
  • We use get_changes for this. One downside is that this doesn't record changes unless meta is changed via the object API. As such, we now have additional hooked functions (hooked into added_order_item_meta and updated_order_item_meta), which are simply recording if meta has been added or updated in any other way, such as via the UI.
  • We have an enqueue-time filter for updates, which drops woocommerce_update_order_item when we didn’t record any actual item changes
  • The send-time filter rebuilds the item payload from DB right before sending, ensuring the final snapshot of the request is sent.

Other information:

  • Have you written new tests for your changes, if applicable?
  • Have you checked the E2E test CI results, and verified that your changes do not break them?
  • Have you tested your changes on WordPress.com, if applicable (if so, you'll see a generated comment below with a script to run)?

Jetpack product discussion

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

Testing instructions:

To test, create a JN site with Jetpack and WooCommerce installed and active. Then on trunk (bleeding edge or release candidate):

  • I haven't been able to reliably come up with reproducable testing instructions for this, but when the issue starts occurring on an order it tends to occur more reliably after that.
  • I'd recommend adding multiple items to an order, at least 4.
  • Modify meta (add meta, change totals) for several. Wait for changes to sync, you may need to re-edit some metas, until you encounter woocommerce_update_order_item being synced. You may find it easier to install the Woo Tax plugin too and ensure tax is applied to each item in an order.
  • You can view synced actions at 89b2f2c10779043189618935e0db614c-logstash (change the blog ID to your blog id)
  • When woocommerce_update_order_item is synced, you should generally notice it is synced for each item in the order, even if only one item has changed.
  • Once you are able to reproduce, you should be able to reproduce consistently, or somewhat consistently in that order with similar actions (perhaps with a delay before taking actions, or after taking other actions on the site), all being well.
  • When you are reproducing, you can also confirm the order item and order item meta details for the same item are correct via wpsh: gpr select * from wp_{BLOGID}_woocommerce_order_items where order_item_id={ID} and gpr select * from wp_{BLOGID}_woocommerce_order_itemmeta where order_item_id={ID}

To test the changes, apply this PR using the Jetpack Beta tester plugin, then follow the same steps.

  • Where you are seeing woocommerce_update_order_item actions synced, there should only be one (not one per item).
  • Run the same tests with wpsh as before, the results should be as expected.

The above tests assume testing with HPOS enabled, but the same applies for legacy order data storage.

@coder-karen coder-karen self-assigned this Dec 1, 2025
@coder-karen coder-karen added [Type] Enhancement Changes to an existing feature — removing, adding, or changing parts of it [Focus] Performance [Status] In Progress [Package] Sync labels Dec 1, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Dec 1, 2025

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/sync-less-woo-update-order-items branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack update/sync-less-woo-update-order-items
bin/jetpack-downloader test jetpack-mu-wpcom-plugin update/sync-less-woo-update-order-items

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
Copy link
Contributor

github-actions bot commented Dec 1, 2025

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 a "[Type]" label (Bug, Enhancement, Janitorial, Task).
  • ✅ 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: January 6, 2026

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

@jp-launch-control
Copy link

jp-launch-control bot commented Dec 1, 2025

Code Coverage Summary

Coverage changed in 1 file.

File Coverage Δ% Δ Uncovered
projects/packages/sync/src/modules/class-woocommerce.php 0/186 (0.00%) 0.00% 68 💔

Full summary · PHP report · JS report

If appropriate, add one of these labels to override the failing coverage check: Covered by non-unit tests Use to ignore the Code coverage requirement check when E2Es or other non-unit tests cover the code Coverage tests to be added later Use to ignore the Code coverage requirement check when tests will be added in a follow-up PR 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 Dec 2, 2025
@coder-karen coder-karen marked this pull request as ready for review December 4, 2025 19:49
@coder-karen
Copy link
Contributor Author

Marking this as on hold for now, as we may remove the woocommerce_update_order_item from being synced entirely which would make this redundant. See SYNC-179.

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

Labels

[Focus] Performance [Package] Sync [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Status] Blocked / Hold [Tests] Includes Tests [Type] Enhancement Changes to an existing feature — removing, adding, or changing parts of it

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants