Add items to user's cart in Craft Commerce 2
In Commerce, a User (or guest with an email address for that matter) can have multiple carts (or unfinished orders).
So we need to get the most recently active one. Something like this should work:
$query = Order::find();
$query-&gt;id($whateverId); // you could also use $query-&gt;email 
$query-&gt;isCompleted(false);
$query-&gt;orderBy('dateCreated DESC');
$cart =  $query-&gt;one();

... // rest of your code