Skip to content

Conversation

@haqadn
Copy link
Contributor

@haqadn haqadn commented Jan 19, 2026

Fixes JETCRM-62

Proposed changes:

Fix: WooSync contact identification for orders with alternative emails

To identify a lead

  • Always use the logged-in customer email as opposed to the billing email.
  • If customer is a guest, use the billing email

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

None

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

None

Testing instructions:

  1. Ensure Jetpack CRM and WooCommerce are active.
  2. Create a WordPress user and a corresponding Jetpack CRM contact.
  3. Log in as the WordPress user on the frontend of your site.
  4. Place a WooCommerce order, but in the billing details, use a different email address than the one associated with the logged-in WordPress user.
  5. Go to the WordPress admin and navigate to the newly created order (WooCommerce > Orders > [Your Order]).
  6. Verify: The "Jetpack CRM Contact" metabox on the order edit page should now correctly display the existing CRM contact associated with the logged-in WordPress user and show "View Contact". Previously, it would show no contact or no "Add Contact" option.
  7. Optional (to test "Add Contact" button): Log out, place an order as a guest using a completely new email address that does not correspond to any existing CRM contact or WordPress user.
  8. Verify: On this new guest order, the "Jetpack CRM Contact" metabox should display "No CRM contact found for this order." and offer an "Add Contact" button.

When a logged-in WooCommerce customer uses a different email address on their
order (e.g., wordpressjentest+different@gmail.com instead of their account
email wordpressjentest@gmail.com), the CRM Contact box on the order page
would fail to identify the existing CRM contact.

This fix adds a helper method get_contact_id_from_order() that:
1. First attempts to find the CRM contact by billing email
2. Falls back to looking up the contact by WordPress user ID if the order
   belongs to a logged-in customer

This ensures that the CRM Contact column in the orders list and the CRM
Contact metabox on the order edit page correctly identify existing contacts
even when customers use alternative email addresses.

Fixes: JETCRM-62

Co-authored-by: adnan007.id <adnan007.id@gmail.com>
@cursor
Copy link

cursor bot commented Jan 19, 2026

Cursor Agent can help with this pull request. Just @cursor in comments and I'll start working on changes in this branch.
Learn more about Cursor Agents

@github-actions
Copy link
Contributor

github-actions bot commented Jan 19, 2026

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!

@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 Jan 19, 2026
…ling email

Per Mike's recommendation:
- First check if order has a WordPress customer (logged-in user)
- If yes, use their account to find CRM contact (by WP user ID link, then by WP user email)
- Only for guest orders, fall back to billing email

This ensures logged-in customers are always identified by their account,
even if they use a different billing email on their order.

Co-authored-by: adnan007.id <adnan007.id@gmail.com>
@jp-launch-control
Copy link

jp-launch-control bot commented Jan 19, 2026

Code Coverage Summary

Coverage changed in 1 file.

File Coverage Δ% Δ Uncovered
projects/plugins/crm/modules/woo-sync/includes/class-woo-sync-woo-admin-integration.php 0/155 (0.00%) 0.00% 21 💔

Full summary · PHP report

Coverage check overridden by I don't care about code coverage for this PR Use this label to ignore the check for insufficient code coveage. .

Simplify changelog entry.
@haqadn haqadn marked this pull request as ready for review January 19, 2026 22:10
Copilot AI review requested due to automatic review settings January 19, 2026 22:10
@haqadn haqadn requested review from a team and mikestottuk January 19, 2026 22:11
@haqadn haqadn added I don't care about code coverage for this PR Use this label to ignore the check for insufficient code coveage. and removed [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. labels Jan 19, 2026
Copy link
Contributor

Copilot AI left a comment

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 fixes an issue in WooSync where CRM contacts were not being correctly identified for orders when logged-in customers used a different billing email address than their WordPress account email.

Changes:

  • Introduced a new helper method get_contact_id_from_order() that prioritizes WordPress user ID over billing email for contact identification
  • Updated order list column and metabox rendering to use the new identification logic
  • Added user-friendly UI feedback when no CRM contact is found

Reviewed changes

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

File Description
projects/plugins/crm/modules/woo-sync/includes/class-woo-sync-woo-admin-integration.php Refactored contact identification logic to prioritize WordPress user account over billing email, and added a new helper method with comprehensive fallback logic
projects/plugins/crm/changelog/fix-woosync-contact-identification-by-wp-user Added changelog entry documenting the bug fix

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4cf9d4511a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +183 to 187
$billing_email = $order->get_billing_email();

// No billing email found, so render message and return.
if ( empty( $email ) ) {
if ( empty( $billing_email ) ) {
?>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Avoid early return for logged-in orders missing billing email

The metabox now uses get_contact_id_from_order(), but it still returns early when billing_email is empty. For logged‑in customers (or admin‑created orders) where the billing email is blank, the helper could still find the CRM contact via the WP user, yet this early return prevents it and shows the “save order to a customer with a billing email” message. This means the new identification logic won’t run in that scenario, so the metabox still fails to show the existing contact; consider only showing this message when there is no WP user and no billing email, or moving the billing‑email check into the guest‑order fallback.

Useful? React with 👍 / 👎.

@haqadn haqadn self-assigned this Jan 19, 2026
Copy link
Member

@manzoorwanijk manzoorwanijk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know how CRM works, so I haven't tested the changes but the code looks good to me.

@haqadn haqadn merged commit 13c6c7a into trunk Jan 22, 2026
78 checks passed
@haqadn haqadn deleted the cursor/JETCRM-62-crm-customer-email-identification-1561 branch January 22, 2026 12:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[CRM] WooSync Module I don't care about code coverage for this PR Use this label to ignore the check for insufficient code coveage. [Plugin] CRM Issues about the Jetpack CRM plugin

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants