I like to call it “Guest Checkout Remorse.” It’s that moment when a customer finishes checking out as a guest, only to realize that this means they cannot log-in to the website to check their order status. So they promptly create an account and then contact customer service to ask if their previous guest order can be linked to their new customer account.
Isn’t customer service wonderful?
While Magento does not provide a way to do this through the admin panel, it’s relatively easy using a couple SQL queries. Simply log in to the MySQL panel of your choice (phpMyAdmin and Adminer are two great options), and execute the following queries:
UPDATE sales_flat_order SET customer_id = (YOUR-CUSTOMER-ID), customer_is_guest=0 WHERE entity_id = YOUR-ORDER-ID AND customer_id IS NULL
UPDATE sales_flat_order_grid SET customer_id = YOUR-CUSTOMER-ID WHERE entity_id = YOUR-ORDER-ID AND customer_id IS NULL
Wondering how to get the right values for customer_id and entity_id? It’s easy. To get the customer_id simply go to Customers > Manage Customers in the Magento admin. Find the customer you’re looking up and click on them as if you’re going to edit their information. When you’re viewing the customer info, the tail end of your URL will look something like this:
In this example, the customer_id is 3193. In order to find the entity_id of the order that was placed using guest checkout, go to Sales > Orders in the Magento admin panel and click on the order to view the details. Look at the tail end of the URL again:
In this example, the entity_id for the order is 16675. Use your values in the SQL query statements shown above and you’ll be all set. You can double-check that the association has been made by going to Customers > Manage Customers in the Magento admin, looking up the customer in question, and you should see the order is now part of their order history.