How ShopMagic handles customers and guest users
How WooCommerce treats guest users
In pure WooCommerce, there is no such entity as a Guest user. Every order not created using an existing WordPress user has its customer data attached as order metadata. Thanks to this, there is no good way to find or group Guest data as every guest exists only in its order context. Simultaneously, the WordPress user is basically treated as a WooCommerce client - A WordPress user with a client role.
Unfortunately, this approach creates some problems with the consistency and performance of the guests' accounts. To list guest users, one would have to:
- Scan all existing WooCommerce orders - which could be millions.
- Decide what identifies unique guests. It could be an e-mail or company name or some taxpayer number.
- Decide which set of guest data to use when there is more than one order from a given guest. One would have to manage the task at hand using this dummy guest that can't be clearly mapped on any other data.
ShopMagic needs to treat Guest users coherently, so we've had to fix this unfortunate WooCommerce behavior.
How ShopMagic treats guest users
In a moment, the user that is not logged in provides an e-mail in any way; ShopMagic creates a Guest account using that e-mail as identifying data. If a guest account with a given e-mail already exists, ShopMagic assumes it's the same guest and allows to overwrite the old guest data with a new one. Besides the e-mail, the guest account also has a numeric unique ID. When a user logs in, the Guest account persists and is not deleted.
This behavior solves most of the major problems with WooCommerce guests:
- Each guest has one place where we can store its data.
- We can easily list/find/get guest data.
- We can easily get the newest guest data.
At the same time, some new issues arise:
- As a new order of the same guest is created, the guest data are overridden.
- It's possible that the given e-mail belongs to both the Guest and the WordPress user. For security reasons, guest data are not transcribed to the existing user.
- It's possible that the guest assigned to the order has different data stored in the order. Therefore customer. E-mail and order.billing_email can be a different e-mail.
What is a Customer entity in ShopMagic
As Guest and WordPress users are different entities, the ShopMagic Customer has been created to facilitate the usage. The customer does not have its own data but is an abstract layer over both entities. When accessing the Customer object, the user/programmer does not need to know if the customer uses a guest entity or WordPress user to access the required data.
As the Customer has a unique ID, the problem with uniqueness between Guest and User arose. WordPress user has its own numeration, and the Guest user also has its own. To solve the problem, the Customer entity has an alphanumeric ID. ShopMagic adds a string prefix to the guest ID, so every Customer ID is always unique and unambiguous.