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):

  • Create an order
  • Add around 5 order items to the order.
  • Wait for these changes to be synced (incremental)
  • Via wpsh confirm the order item and order item meta details for one item are synced:
    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}
  • Modify the 'Total' amount for a line item and click 'Save'
  • Notice the following synced actions: 1 updated_order_item_meta for the order (object) item id in question, 1 woocommerce_update_order_item for every item in the order (in this case should be 5), 1 woocommerce_after_order_object_save
  • Via wpsh, confirm the order item and order item meta details for the same item are correct (the item meta _line_total should be the only thing to change).
  • Also via wpsh, check other items and item meta in that order, to confirm nothing else has changed.
  • Similarly, if you 'add meta' for an item, you should see 1 woocommerce_update_order_item for every item in the order (in this case should be 5), and 1 woocommerce_after_order_object_save, being synced.
    For changes that affect multiple items:
  • If you click on 'Recalculate', when nothing has changed, you should see one woocommerce_after_order_object_save being synced.
  • Then, add a new tax rate (standard), and click 'Recalculate'. You should see updated_order_item_meta and woocommerce_update_order_item actions firing for each item id.

To test the changes, apply this PR using the Jetpack Beta tester plugin, then:

  • Modify the 'Total' amount for a line item.
  • Notice the following synced actions: 1 updated_order_item_meta for the order (object) item id in question, 1 woocommerce_update_order_item for the same item id, 1 woocommerce_after_order_object_save
  • Run the same tests with wpsh as before, the results should be as expected.
  • For the 'add meta' test, you should only see the new meta key synced if it is whitelisted (eg 'rate_id')
  • When clicking 'Recalculate' if nothing has changed, you should see the same as before.
  • Similarly when clicking 'Recalculate' after updating the tax rate, you should see the same as before as well. Confirm via wpsh that changes are reflected.

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:

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.

@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
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] In Progress [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