Link a Guest Order to a Customer Account in Magento

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.

H/T Fran and R.S at Stack Overflow. Copied and expanded here for my reference.

Published by

Brian Lyman

Brian is the founder of Vale Studios, which is really just a stage name for what has been a great experience in freelancing. Brian is currently working under a dedicated contract for a terrific e-commerce retailer, but he uses this space to continue publishing ideas and reflections related to e-commerce, marketing, and Magento.

3 thoughts on “Link a Guest Order to a Customer Account in Magento”

  1. I’ve noticed rare instances within my install where orders are placed by customers with valid accounts but the order doesn’t get linked to the customer’s account (although the customer’s account group seems to link without issue).

    The resolution basically follows the steps you’ve outlined above (locate the customer’s account ID, update customer_id in sales_flat_order and sales_flat_order_grid where increment_id = , etc.).

    With regards to the Account Information displayed on the Order View, that data is stored in sales_flat_order and is easily changed. That data is contained in the customer_email, customer_firstname, customer_lastname fields. These fields don’t appear to have any foreign key constaints, so just remove the NULL values and update with the correct customer information.

  2. Ever have issues with doing this then going in the back end finding the customer to create another order and when the new order is created it has created from under that customer it then creates a NEW customer with the same info?

Leave a Reply to Nick Cancel reply

Your email address will not be published. Required fields are marked *