Skip to content

Conversation

@staskus
Copy link
Contributor

@staskus staskus commented Aug 28, 2025

WOOMOB-1045

Description

Customer details are incorrect after opening the customer search in order creation.

This issue led me down a confusing path of figuring out how customers work in the WooCommerce iOS app. There are two main types: WCAnalyticsCustomer from the wc-analytics/customer endpoint, and Customer from the /customers/{user_id} endpoint.

WCAnalyticsCustomer represents customers created when placing an order, while Customer represents registered site users (wp-admin -> users). These can be linked through WCAnalyticsCustomer.user_id (which points to Customer.id), and Customer.id (which matches WCAnalyticsCustomer.customerID). The user_id is 0 if the analytics customer is not a registered WordPress user.

It gets more complicated on iOS. Even when calling the wc-analytics/customer endpoint, the app persists data in both Storage.WCAnalyticsCustomer and Storage.Customer. The name Storage.Customer suggests it represents a Customer from /customers/, but in practice it is a shared aggregate object combining data from both WCAnalyticsCustomer and Customer.

The problem is that Storage.Customer only has a single identifier, customerID. Sometimes this field stores the customerID value, and other times it stores the userID value. The app uses these values interchangeably, which creates inconsistencies. For example, retrieveCustomer asks for a customerID parameter by name, but actually requires the WordPress userID to succeed. This kind of mismatch appears throughout the Customer implementation in the app. Also, given that both of these types are updated from one another, some data losses in the conversion process are possible.

This made it difficult to identify the real cause of the bug. In the end, it came from the fact that we create Storage.Customer from WCAnalyticsCustomer during order creation with incomplete mapping, and later use Storage.Customer within Menu -> Customers -> Details:

  1. Order Creation → Add Customer Details
  2. wc-analytics/customers call is made
  3. Storage.Customer entities are deleted
  4. Storage.Customer is re-inserted and mapped with wc-analytics/customers data, but shipping information is not set
  5. The Menu -> Customers list shows WCAnalyticsCustomer data, but when tapping on a customer, the details come from Storage.Customer (which had been deleted and remapped without shipping information after opening the order).

I’m applying a simpler fix first, but I also plan to introduce a larger refactor to bring more clarity to the codebase. Hopefully, this will also uncover other hidden issues in the process:


Do you want me to also make it slightly more structured for a GitHub issue/PR description (with headings like Background, Problem, Root Cause, Fix)? That would make it easier for reviewers to parse.

Steps to reproduce

  1. Log in to a test store.
  2. Open Menu > Customers and confirm that customers' locations are correct. Billing & shipping addresses are correct if available, otherwise, only Location is displayed.
  3. Open Orders > + to add new order.
  4. Select Add customer details > select any customer > dismiss the form.
  5. Confirm customer shipping/billing data is shown.
  6. Switch back to Menu > Customers.
  7. Confirm location information is still displayed.

Testing information

iPad Air 18.5 simulator, tested with WordPress and guest users

Screenshots

Simulator.Screen.Recording.-.iPad.Pro.11-inch.M4.-.2025-08-28.at.23.02.29.mov

  • I have considered if this change warrants user-facing release notes and have added them to RELEASE-NOTES.txt if necessary.

…ation

In the order creation, when customer details view is opened:

1. We make a call to wc-analytics/customers to fetch customers who made past orders
2. WCAnalyticsCustomer is mapped to Storage.Customer, however, we don't map all the available data in the WCAnalyticsCustomer, making shipping details get lost
@staskus staskus added this to the 23.2 milestone Aug 28, 2025
@wpmobilebot
Copy link
Collaborator

App Icon📲 You can test the changes from this Pull Request in WooCommerce iOS Prototype by scanning the QR code below to install the corresponding build.

App NameWooCommerce iOS Prototype
Build Numberpr16055-1cae605
Version23.1
Bundle IDcom.automattic.alpha.woocommerce
Commit1cae605
Installation URL2759lc8rjtfco
Automatticians: You can use our internal self-serve MC tool to give yourself access to those builds if needed.

@staskus
Copy link
Contributor Author

staskus commented Aug 28, 2025

@iamgabrielma @toupper I've seen both your names in history. You may remember more context. As I mentioned in the description, I got a bit lost in the customer implementation. The fix is working and make sense but maybe there are another points where things need to be improved.

I also attempted a broader refactoring here #16056 but it needs more testing.

@iamgabrielma iamgabrielma self-assigned this Aug 31, 2025
@iamgabrielma
Copy link
Contributor

iamgabrielma commented Aug 31, 2025

Thanks for the fix!

@iamgabrielma @toupper I've seen both your names in history. You may remember more context. As I mentioned in the description, I got a bit lost in the customer implementation. The fix is working and make sense but maybe there are another points where things need to be improved.

From my recollection, the need of using the /wc-analytics/customers endpoint (it is still an undocumented route it seems...) came up when searching customers to assign them to orders, the existing endpoint at the time was /v3/customers which had several limitations, ie: Only returned registered customers (despite customers being able to checkout without registration), and these were only searchable by registered customer_email, but not by name or surname. I'm not quite sure if this has changed since then, Corey posted some details here.

The discrepancy with customerID and userID comes from the same place, as userID is zero in core when the customer is non-registered, if you have 10 non-registered customers, then you have 10 users with the same userID 0, which wouldn't work in the client to differentiate them, hence the addition of customerID for the app, this tracks non-registered customers as well.

As you mention I cannot see any issue with adding billing/shipping address as a quick fix, it does make sense, specially when we already map some of those fields for name/email.

@staskus
Copy link
Contributor Author

staskus commented Sep 2, 2025

Thanks for the context @iamgabrielma! Merging this fix...

@staskus staskus merged commit ff9ee39 into trunk Sep 2, 2025
25 of 27 checks passed
@staskus staskus deleted the woomob-1045-customer-details-are-incorrect-after-opening-customer-search branch September 2, 2025 11:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants