I've got some orders from the guest user and later they create their account and ask to link the old orders. How can I Do it? Please Help

3 Answers 3


Using SQL -

UPDATE sales_order SET customer_id = {YOUR CUSTOMER ID}, customer_is_guest = 0 where entity_id = {YOUR ORDER ID};
UPDATE sales_order_grid SET customer_id = {YOUR CUSTOMER ID} where entity_id = {YOUR ORDER ID};

Using Extension -

Have a look at this solution - https://github.com/magepal/magento2-guest-to-customer

You can get some idea and customize it as per yours need.

  • Without using an extenstion Nov 2, 2021 at 5:31

Obtain the customer and the order from repositories and then:



Finally, I got the solution for the above Question For Magento 2 Programatically!


use Magento\Framework\App\Bootstrap;
use Magento\Customer\Api\AccountManagementInterface;
use Magento\Customer\Model\AccountManagement;

$bootstrap = Bootstrap::create(BP, $_SERVER);
$objectManager = $bootstrap->getObjectManager();

$state = $objectManager->get('Magento\Framework\App\State');

$email = 'xxxx@gmail.com'; // Your Customer Id
$incrementId = '000000047'; // Your Order Increment Id from Admin Listing

$toCustomer = $objectManager->create('Magento\Customer\Model\Customer')->setWebsiteId(1)->loadByEmail($email);

$orderbyid = $objectManager->create('Magento\Sales\Model\Order')->loadByIncrementId($incrementId);

echo "Done";

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.