-
Notifications
You must be signed in to change notification settings - Fork 10.8k
Link guest order to user account by email match #29138
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
As a sidenote, Shopify does this automatically for you. If you create an account after you've made an order, it will automatically assign your past orders to your new account. |
Hi @galbaras, Thank you for taking the time to share this idea, we really appreciate your help. While this is clearly a great improvement/idea we won’t be able to tackle it in the upcoming weeks. We’re going to add it to our backlog where it will be considered for future releases. Stay tuned for updates. |
@galbaras This is actually a very good idea. |
Yes, this functionality is a necessary improvement for any store that offers the ability to checkout as either a guest or registered user—where a guest wants to register at a later time. @galbaras - in case you aren't aware, you can manually link orders under: Thank you @zhongruige for keeping this ticket open and considering this much-needed functionality. |
@theprofessor101 Actually, I can't see "Actions" on the reports page you've specified, and the only customers listed are those who are already users. A notice on the page recommends using the new Analytics pages, but there's no customer report there and nothing relevant in the settings. If there was ever a way to link guest posts to users after they register, attaching it to an action, and scheduling it, should be very easy. It just needs to be done. |
@galbaras Hmm, interesting that you can't see it. I'm sure you're in the right area, but just by chance make sure you select "WooCommerce > Reports > Customers..." and not "WooCommerce > Customers". The organization is a little bit confusing. In the screenshot below you'll see 3 icons in the right column. If there are orders to link, there will be a 4th icon for "Link Previous Orders". |
I definitely went to the right place, but there were no linkable orders where I looked. Found it now. Awesome function. I hope it will stay when the reports area is removed... Also, I still think this should be automatic. I'm happy to check a box once to indicate I want it done automatically, but after that, it should be done automatically, either during registration or in the background. |
Yes. This has become a nightmare since no one creates an account on the first checkout and customer usually create it afterward and their older orders are not linked once he creates it. Would really like it if this basic functionality is included. |
@galbaras I actually use a code snippet to mimic this functionality. I usually create the account for the customer once he checked out and link it. Here is the code snippet for anyone else to use: ``
} //add this newly created function to the thank you page |
@John-belt Thank you for this code snippet. Creating users automatically can be a valuable option, which the WooCommerce team should consider. Personally, I don't want to force customers to become users, but it's good to know about the So the solution should be to have a scheduled task that executes this function for every user found in new orders created since the last run (the first one may be massive, but that's a small price to pay). WooCommerce Team (@zhongruige), what do you say? |
Yes, it's not a good solution but it gets the work done in the meantime. Personally, I would prefer the order linking once the user wants to create the account as you said. This is very important for repeat customers who come back to your site and then decide to create an account. I have numerous customers complaining to me that they cannot see their past orders after creating account. Hope the woo team will consider this as an important feature. |
Hi @galbaras! Thank you for the tag! It requires further feedback from the WooCommerce Core team. I am adding the Please note it may take a few days for them to get to this issue. Thank you for your patience. |
It's been 40 days. Any news? |
Hi @galbaras. We think that this is a reasonable feature request so I'm going to mark it as enhancement. A note on implementation, though: the link of existing orders to new customers would be created not when the customer creates an account, but when the email is verified, for security reasons. |
Buying as a guest has always a trick for the system and privacy/security concerns. Guest checkout, what can happen:
A simple workflow could be:
But there are situations when a user can buy using a wrong email address and if an account exists with that email, the order will be attached to a wrong customer. This is not good, but this can happen even if the guest checkout is not enabled. A customer can create an account during checkout using a wrong email address and the order will be mailed to that email because we can’t validate that information during the checkout. Forcing the customer to register or log in before the checkout is the best scenario, with a cost of course. This is the only way to avoid user fails because when registering we can validate that email. |
As per reply from @Konamiman
WooCommerce Team, will this be released any time soon? |
For those adventurous souls that don't mind a little crazy database work I think I have a solution. If you're not a DB fan avert your eyes... I could very well be wrong, but it looks to me like the association between Anyway - I made a trigger that fires after a user is created by registration (or otherwise) and it's working for me perfectly: DELIMITER $$
CREATE TRIGGER after_users_insert
AFTER INSERT
ON wp_users FOR EACH ROW
BEGIN
update wp_postmeta a
join wp_postmeta b
on a.post_id = b.post_id
set b.meta_value = NEW.ID
where a.meta_key = '_billing_email' and a.meta_value=NEW.user_email
and b.meta_key = '_customer_user' and b.meta_value='0';
END$$
DELIMITER ; I can see how this might be viewed as a Really Bad Idea - but I like databases and am very comfortable with triggers and SQL. The change here is so, so small that I can't see it breaking anything in the future - it's just an update to a single row after all. If you're wondering about the funky self-join, that's just how WP does it's weird database thing. Such a strange design, but it's an old, old system isn't it! Anyway - I hope this helps you if you need it. There's one massive advantage to using this trigger and it's that it's really really fast. From what I've read - the solutions out there need to use Woo/WP internal find/update stuff which is slow because, I think, it has to loop over all the orders in memory. That's what I read anyway I have no idea I don't do PHP but I'll be honest: it wouldn't surprise me. |
I'm going to echo the obvious... using this SQL to do this is a really bad idea. Do things through the WP/WC API because it does important things like cache invalidation and running other hooks that might be important. Regardless, this being in core WC is long overdue... like so many sensible enhancements. What is funny is I found this issue as a frustrated customer (mistakenly bought something as a guest and then angry it didn't show up later when I created an account, on what is obviously a WC site. This is commonly automatically done on other e-commerce solutions. The "security" concerns of what happens when someone checks out as a guest with the wrong email, and then someone alter comes along and registers and account with that email seems easy to work out. The identity of the person who used guest wouldn't be revealed here, just that they input the email owners email. The concern would be exposing the shipping and/or billing address of that person, so don't. Don't import billing/shipping address (or phone/etc) from a guest order to a profile unless it matches what is input by the account owner. |
I was also looking for this functionality. It's hard to believe that WC doesn't have this built in, and that this thread has been going since Feb 2021. Seems like an important feature, but I guess the team at Woocommerce disagree. Whilst on my search I came across this solution:
My understanding is that will create the link to old orders, when a new user is registered. I've yet to test it. If it works, it might be helpful for people wishing to achieve this outcome. |
We're using this and it has been working great so far: /**
* Automatically assign new orders to existing user account if it exists.
* This is based on billing email address.
*/
function assign_order_to_existing_account()
{
if( !is_user_logged_in() && !empty( $_POST['billing_email'] ) )
{
$user = get_user_by( 'email', $_POST['billing_email'] );
if( !empty( $user ) )
{
wp_set_current_user( $user->ID );
}
}
}
add_action( 'woocommerce_checkout_process', 'assign_order_to_existing_account', 1 ); Edit: Sorry I just read the OP and saw that this is about linking past orders to newly created accounts. I subscribed here as we were keen to do that, but failing a solid solution we've done the above so that we at least capture any new orders being made. We're also automatically creating an account for any order if an account doesn't already exist so all orders are now associated with an account, there are no new "guest" orders. Also for account creation during checkout, no password needs to be set, so it avoids adding further friction to the purchasing process. |
@inspiredearth Thank you so much for this. This makes me wonder (yet again) why previous orders aren't linked to new customers by default and why the WooCommerce team isn't making it a default action now that we're asking for it. |
This is perfect / what I needed. Thank You. I agree that it seems like this should be a default functionality in WooCommerce, with maybe a checkbox in settings to disable it if that's what you want to do, but we've had many customer service issues around people saying "I placed an order and it's not in My Account > Orders History" so it seems this is the functionality that users expect, too. |
A user mentioned this as well in HC-35910760 |
Noting a Woo customer with this issue: 7084700-zen |
No message appears but it has stopped linking. |
Has this been implemented yet? |
Does anybody know if this is implemented? Thanks |
Not that I'm aware of. I gave up hoping, waiting, and praying for Woo to listen, care, and implement much-needed basic functionality such as this. This thread was started in 2021, yet three years later nothing but hopelessness. After six years of running our business via Woo, I finally had enough and moved our entire store of 800+ SKU's to another provider (starts with the letters S, H, O, P, I...). The funny thing, after exporting/importing all customers and orders, this other website connects them all together. When a customer creates an account (with the same email used when placing the orders), all—yes ALL past orders show up. Amazing! |
This is a seriously needed improvement. All modern shopping carts do this and customers simply assume its how it works now. Creates headaches for store owners and causes trust issues for customers when they can't find their newly purchased order. Sad to see woocommerce hasn't implemented this in the past three years since it was first brought up. |
looking too |
Dear enjoyers of cold sweat in the face of potential sales. `add_action( 'woocommerce_checkout_update_order_meta', 'auto_assign_customer_data_to_order' ); function auto_assign_customer_data_to_order( $order_id ) {
}` credits: https://de.wordpress.org/support/topic/gast-bestellung-automatisch-adresse-zuweissen/#post-157358 |
dont know why the code get fucked up |
Old thread that urgently needed attention from the development team. |
here is a plugin that solve the same issue |
Thank you for the initiative, this will make a big difference to the community. However, it still doesn't work (for me). Below are some considerations that may help: Main Functionality Instead of using the WC_Customer class to create a new user, it may be more straightforward and efficient to use the wp_insert_user() function to create a WordPress user and then associate the additional WooCommerce information. The code currently only creates users for orders placed in the admin area (is_admin()). If the goal is to create users for all guest orders (including those placed on the front-end), you may need to remove this condition or adjust the logic to check for orders properly. Although you are catching exceptions, there is no log to store these error messages. Logging these errors (e.g. using the error_log() function) can be useful for debugging purposes and to monitor potential issues. Some of the code, such as the address settings for billing and shipping, could be simplified. You may want to create a function to avoid code repetition. The deactivate() method clears some configuration options, but it does not necessarily need to remove all options when deactivating the plugin. It may be more appropriate to keep the options if the plugin is reactivated. When using wp_new_user_notification(), make sure it uses the correct parameters for the notification, as the function may vary between versions of WordPress. |
Does anyone have a full solution for this yet? By that I mean:
Users registering and complaining that their previous guest orders aren't listed is now a semi-regular occurrence for me. Ideally this would be built-in to WooCommerce, but I'd settle for a plugin or code that I can add to the child theme. |
I think it's a must for WooCommerce and I also think it's a shame that this basic functionality has not been considered and implemented for years. |
Available on Wordpress plugin create-user-from-guest-order This plugin is now updated, do checkout, 🙌 Features Include
|
Thanks for the tip about a plugin. However, it should not be an advertising event here, but should rather be about the basic discussion that this elementary feature, which all known store systems have by default, should also be implemented in the core of WooCommerce. |
I disagree. Having this (GPL) plugin means that the WooCommerce team can integrate its code into its own plugin, possibly as a set of optional features. @s-azizkhan could not have made it much easier. Let's all test this plugin and post our experiences here. Maybe the WC team will oblige then. @s-azizkhan Quick question: if I only want to link orders to new users created by the customers, how do I configure your plugin? Do I need to check anything? Do anything? |
@galbaras The mentioned plugin's linkPastOrdersToUser feature (no extra config required) ensures that all past orders from guests (those without a registered user) are linked to the user once they are created (match by email). To only link new orders to users (i.e., prevent the plugin from linking past orders to newly created users), you simply need to disable the part of the code that handles linking past orders. If you think this can be improved, please open an issue on the plugin |
@triopsi Looking at the WooCommerce code, it looks like |
This feature is highly requested and I wish woocmmerce team add this |
I find it strange that such an elementary and basic feature is not included in WooCommerce Core. I also can't find a real reason why it hasn't been implemented like this? Or is there a blog post or explanation somewhere that I don't see? |
On shops that allow guest checkout (good for conversion), customers sometimes create an account after they've ordered, particularly if they're ordering again. However, their guest orders remain disconnected from their new user account.
My request is that orders be linked to new user accounts automatically.
This can be done as soon as the account is created by searching for guest orders with a matching email address. Doing it this way allows the system to display those orders and get confirmation from the new user before linking them.
Alternatively, it can be done by a background job, which links users with a "customer" role created since the last job ran with matching orders.
The text was updated successfully, but these errors were encountered: