Sync WooCommerce module: Start syncing customer account detail changes stored in user meta#49551
Sync WooCommerce module: Start syncing customer account detail changes stored in user meta#49551fgiannar wants to merge 5 commits into
Conversation
|
Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.
Interested in more tips and information?
|
|
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
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:
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:
If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack. |
Code Coverage SummaryCoverage changed in 1 file.
Full summary · PHP report · JS report Coverage check overridden by
Covered by non-unit tests
|
c7c1b2b to
3c1e46b
Compare
There was a problem hiding this comment.
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_metafor whitelisted WooCommerce customer meta keys and batch updates per user untilshutdown. - 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). |
| return; | ||
| } | ||
|
|
||
| $updated_props = $this->get_customer_detail_props( array( $meta_key ) ); |
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
Thank you, this looks good and tests well for me. Left a non-blocking comment.
Related to ACTLOG-53
Proposed changes
added_user_meta,updated_user_meta, anddeleted_user_meta, batch tracked customer meta changes per user for the request, and emit a customjetpack_updated_woo_customer_metaSync action onshutdown.WP_User-shaped customer object as arg 0 and sanitized changed WooCommerce customer prop names as arg 1.paying_customertois_paying_customer.session_tokens,first_name, andlast_name.delete_user/wpmu_delete_userflows so deleting a customer does not also enqueue a customer detail update.Related product discussion/links
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:
billing_email,shipping_city, oris_paying_customer.The synced payload does not include:
WC_Customerobject.Testing instructions
Automated
From a Jetpack checkout with the Docker test environment installed:
Expected:
test_customer_meta_updates_are_synced_without_customer_datapasses.test_non_customer_meta_updates_are_not_synced_as_customer_detailspasses.test_customer_meta_filter_rebuilds_minimal_customer_objectpasses.test_customer_meta_deletes_from_user_deletion_are_not_synced_as_customer_detailspasses.Manual
wp-admin/user-edit.php, such as billing email, billing city, shipping city, or billing phone.jetpack_updated_woo_customer_metaaction.WC_Customer.billing_emailandshipping_city.first_name,last_name, or session-token data, and confirm it does not producejetpack_updated_woo_customer_meta.jetpack_updated_woo_customer_meta.