Skip to content

Sync WooCommerce module: Start syncing customer account detail changes stored in user meta#49551

Open
fgiannar wants to merge 5 commits into
trunkfrom
add/sync-woo-customer-props-updated
Open

Sync WooCommerce module: Start syncing customer account detail changes stored in user meta#49551
fgiannar wants to merge 5 commits into
trunkfrom
add/sync-woo-customer-props-updated

Conversation

@fgiannar

@fgiannar fgiannar commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Related to ACTLOG-53

Proposed changes

  • Add WooCommerce Sync handling for customer account detail changes stored in user meta.
  • Listen for added_user_meta, updated_user_meta, and deleted_user_meta, batch tracked customer meta changes per user for the request, and emit a custom jetpack_updated_woo_customer_meta Sync action on shutdown.
  • Send a minimal WP_User-shaped customer object as arg 0 and sanitized changed WooCommerce customer prop names as arg 1.
  • Map tracked WooCommerce user meta keys to customer prop names, including paying_customer to is_paying_customer.
  • Ignore unrelated or already-covered user meta such as session_tokens, first_name, and last_name.
  • Skip customer meta cleanup from delete_user/wpmu_delete_user flows so deleting a customer does not also enqueue a customer detail update.
  • Validate the payload before enqueueing so invalid customer objects, empty prop lists, untracked props, and overfull customer objects are not synced.
  • Add Sync test coverage for tracked customer meta updates, untracked user meta updates, filter hardening, and user-deletion cleanup.

Related product discussion/links

  • ACTLOG-53
  • Requires the WPCOM receiver/display counterpart for end-to-end Activity Log rendering.

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

Yes. This introduces a new Sync action for WooCommerce customer account detail updates.

The synced payload includes:

  • A minimal user object: local user ID, display name, login, and email.
  • Sanitized changed prop names, such as billing_email, shipping_city, or is_paying_customer.

The synced payload does not include:

  • Raw billing, shipping, phone, or address values.
  • The full WC_Customer object.
  • Session tokens or unrelated user meta.
  • Customer meta cleanup triggered by deleting the corresponding WordPress user.

Testing instructions

Automated

From a Jetpack checkout with the Docker test environment installed:

JETPACK_TEST_WOOCOMMERCE=1 jp docker phpunit jetpack -- --filter=Jetpack_Sync_WooCommerce_Test

Expected:

  • test_customer_meta_updates_are_synced_without_customer_data passes.
  • test_non_customer_meta_updates_are_not_synced_as_customer_details passes.
  • test_customer_meta_filter_rebuilds_minimal_customer_object passes.
  • test_customer_meta_deletes_from_user_deletion_are_not_synced_as_customer_details passes.

Manual

  1. Apply this Jetpack branch to a connected test site with WooCommerce active.
  2. Apply the WPCOM receiver/display counterpart to the sandbox used for Activity Log testing: 222803-ghe-Automattic/wpcom
  3. Create or use a WooCommerce customer associated with a WordPress user.
  4. Update tracked WooCommerce customer fields from wp-admin/user-edit.php, such as billing email, billing city, shipping city, or billing phone.
  5. Update tracked WooCommerce customer fields from the customer's My Account address screens.
  6. Trigger or wait for Sync processing.
  7. Inspect the synced jetpack_updated_woo_customer_meta action.
  8. Confirm arg 0 is a minimal user object, not a full WC_Customer.
  9. Confirm arg 1 contains changed prop names, such as billing_email and shipping_city.
  10. Confirm the payload does not include the raw updated billing or shipping values.
  11. Confirm the WPCOM Activity Log entry lists the modified fields once the receiver/display counterpart is applied.
  12. Update unrelated user meta, such as first_name, last_name, or session-token data, and confirm it does not produce jetpack_updated_woo_customer_meta.
  13. Delete a WooCommerce customer user that has tracked customer meta and confirm the deletion cleanup does not produce jetpack_updated_woo_customer_meta.

@github-actions

github-actions Bot commented Jun 11, 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 add/sync-woo-customer-props-updated branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack add/sync-woo-customer-props-updated
bin/jetpack-downloader test jetpack-mu-wpcom-plugin add/sync-woo-customer-props-updated

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 [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Tests] Includes Tests labels Jun 11, 2026
@github-actions

github-actions Bot commented Jun 11, 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: July 7, 2026
    • Code freeze: July 6, 2026

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

@fgiannar fgiannar added the [Status] Needs Privacy Updates Our support docs will need to be updated to take this change into account label Jun 11, 2026
@jp-launch-control

jp-launch-control Bot commented Jun 11, 2026

Copy link
Copy Markdown

Code Coverage Summary

Coverage changed in 1 file.

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

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 .

@fgiannar fgiannar 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 Jun 11, 2026
@fgiannar fgiannar force-pushed the add/sync-woo-customer-props-updated branch from c7c1b2b to 3c1e46b Compare June 12, 2026 07:16
@fgiannar fgiannar requested a review from Copilot June 12, 2026 08:17

Copilot AI 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.

Pull request overview

This PR extends the Sync WooCommerce module to track changes to WooCommerce customer account details stored in user meta and emit a new batched Sync action (jetpack_updated_woo_customer_meta) containing a minimal customer object and a sanitized list of changed prop names.

Changes:

  • Track added_user_meta / updated_user_meta / deleted_user_meta for whitelisted WooCommerce customer meta keys and batch updates per user until shutdown.
  • Enqueue a new Sync action (jetpack_updated_woo_customer_meta) and validate/sanitize its payload before enqueueing.
  • Add PHPUnit coverage to verify tracked meta updates sync prop names without syncing raw customer field values.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
projects/packages/sync/src/modules/class-woocommerce.php Adds customer-meta tracking, batching on shutdown, payload filtering, and minimal customer object builder for the new Sync action.
projects/plugins/jetpack/tests/php/sync/Jetpack_Sync_WooCommerce_Test.php Adds tests covering tracked vs untracked user meta updates and verifying no raw customer meta values are synced.
projects/packages/sync/changelog/add-woocommerce-customer-updated-props-sync Adds changelog entry for the new customer-updated-props Sync behavior.
projects/plugins/jetpack/changelog/add-sync-woo-customer-props-updated Adds Jetpack changelog stub indicating no user-facing entry is needed (tests-only change).

Comment thread projects/packages/sync/src/modules/class-woocommerce.php Outdated
Comment thread projects/packages/sync/src/modules/class-woocommerce.php Outdated
@fgiannar fgiannar added [Status] Needs Review This PR is ready for review. and removed [Status] In Progress labels Jun 12, 2026
@fgiannar fgiannar requested a review from coder-karen June 12, 2026 08:55
@fgiannar fgiannar changed the title Sync WooCommerce module: Start syncing 'woocommerce_customer_object_updated_props' actions Sync WooCommerce module: Start syncing customer account detail changes stored in user meta Jun 12, 2026
return;
}

$updated_props = $this->get_customer_detail_props( array( $meta_key ) );

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.

get_customer_detail_props fires on every user meta write, and includes an in_array call, which I believe could be avoided by checking the key early. Something like this could work?

	public function maybe_sync_customer_meta_update( $meta_id, $user_id, $meta_key, $value ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
		$customer_id = (int) $user_id;
		if ( $customer_id <= 0 ) {
			return;
		}

		if ( 'deleted_user_meta' === current_action() && isset( $this->deleted_user_ids[ $customer_id ] ) ) {
			return;
		}

		$meta_key = sanitize_key( (string) $meta_key );

		if ( ! isset( self::$customer_detail_meta_key_to_prop[ $meta_key ] ) ) {
			return;
		}
		$prop = self::$customer_detail_meta_key_to_prop[ $meta_key ];

		if ( ! isset( $this->customer_meta_updates[ $customer_id ] ) ) {
			$this->customer_meta_updates[ $customer_id ] = array();
		}

		$this->customer_meta_updates[ $customer_id ][ $prop ] = true;
	}

@coder-karen coder-karen 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.

Thank you, this looks good and tests well for me. Left a non-blocking comment.

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/ [Status] Needs Privacy Updates Our support docs will need to be updated to take this change into account [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