A disclaimer first: please make sure this is legal in your country and also that your checkout visitors are aware they will become registered customers without explicit consent (i.e. without ticking a “create an account on this site” checkbox).
So, yeah, there is a way to turn guest checkouts into registered customer ones. Also, there is a neat WooCommerce function to bulk add all past guest orders to a new customer (wc_update_new_customer_past_orders).
Of course, “Allow customers to place orders without an account” must be enabled in your WooCommerce settings, otherwise you’re not allowing guest checkouts and the snippet will be irrelevant.
So, here’s the fix. Enjoy!
PHP Snippet: Automatically Register Guest Customers @ WooCommerce Checkout (and Programmatically Log Them In @ WooCommerce Thank You Page)
You can place PHP snippets at the bottom of your child theme functions.php file (delete "?>" if you have it there). CSS, on the other hand, goes in your child theme style.css file. Make sure you know what you are doing when editing such files - if you need more guidance, please take a look at my free video tutorial "Where to Place WooCommerce Customization?"
Does this snippet (still) work?
Please let me know in the comments if everything worked as expected. I would be happy to revise the snippet if you report otherwise (please provide screenshots). I have tested this code with Storefront theme, the WooCommerce version listed above and a WordPress-friendly hosting on PHP 7.3.
Check out these free video tutorials. You can learn how to customize WooCommerce without unnecessary plugins, how to properly configure the WooCommerce plugin settings and even how to master WooCommerce troubleshooting in case of a bug!
Business Bloomer Founder
Author, WooCommerce expert and WordCamp speaker, Rodolfo has worked as an independent WooCommerce freelancer since 2011. His goal is to help entrepreneurs and developers overcome their WooCommerce nightmares. Rodolfo loves travelling, chasing tennis & soccer balls and, of course, wood fired oven pizza.
13 thoughts on “WooCommerce: Automatically Register Guest Checkouts”
I dont know why, but it doesnt work for me. It is not creating new ser from guest order…
Not sure, works for me!
Hello, I noticed that although the new orderer receives a user account, the data from the order (name, address, city, zip code, etc.) is not transferred to the master data of the user account. These are only stored in the order, i.e. the user must enter his data again with the next order. Is this correct or a bug with me? Thanks for the great snippet. Best regards, Oliver
There may be another set of code for that, please test the following (add it BEFORE the wc_update_new_customer_past_orders line):
This should save WordPress user name, last name and display name. If this works let me know and I’ll add more code to save also billing & shipping
I’ve set this up in a child theme, but how do I get it to kick in so it creates an wp role for the existing guest customers?
A role which is not “customer”?
This works, but I noticed it slows down WooCommerce a LOT. When I place an order, it takes forever to get to the checkout and then confirm the order. I assume he is searching all customers records first trying to find the matching email? If I remove the snippet, the speed is back to normal. Any ideas if this can be avoided?
Let me update. I ran it again, and it seems like the lag was not because of this snippet. It might have been a temporary thing on the server and the snippet does not seem to slow down anything. Sorry about that. 🙂
No prob at all!
Thanks for This! Really helps a lot! I just want to know if you have a related tutorial where order from guest checkout can be sync if customer created an account? Thank you!
Hey Jovan, wc_update_new_customer_past_orders() function already does that
If this Snippet removes the Create account password on checkout, then how would the customer access their account?
Hi Brooke! wc_create_new_customer should already email account details to customer – please test and let me know