How do I programmatically change the user ID in a order? I programmatically created a user using the following code.

use Drupal\user\Entity\User;

/**
 * Helper function to create a new user.
 */
function create_new_user() {
  $user = User::create();
  $user-&gt;setPassword('&lt;password&gt;');
  $user-&gt;enforceIsNew();
  $user-&gt;setEmail('&lt;email&gt;');
  $user-&gt;setUsername('&lt;username&gt;');
  $user-&gt;save();
  drupal_set_message("User with uid " . $user-&gt;id() . " saved!\n");
}


Now I need to set the ID of the created user into an order. 

I've loaded the order using the following code.

$ord_id = 10;
$order = \Drupal::entityTypeManager()-&gt;getStorage('commerce_order')-&gt;load($ord_id);


I want to update the user ID of this order. How can I achieve this?
It should be as simple as:

$order-&gt;setCustomer($user)-&gt;save();


Or if you only have the user ID and don't want to load the account object:

$order-&gt;set('uid', $uid);
$order-&gt;save();