Assigning (adding) an entity reference when an Order process is completed In Drupal 8, I am needing to know how to assign/add an entity reference of an e-book to an multivalue entity reference field of the user when an order with the e-book is placed. This will allow the user to then access only the e-books attached to his user account.

What hook do I use? how do I know if there is a product in the order that have field_ebook=true? Then how do add it to the list of entity references?
Not a hook but an event.

Orders have an attached workflow. You can listen to the event of an order being placed, see the state_machine module for documentation on this. Basically, you need to define an event subscriber service, subscribe to the event commerce_order.place.post_transition, then check if order is an ebook and if so act based on the order customer ID.

The subscriber method needs like this:

public function orderStateChange(WorkflowTransitionEvent $transition_event) {
  $entity = $transition_event-&gt;getEntity();
  // Check the transition id and whetever else you need on the order and then do your thing.
  if ($transition_event-&gt;getToState()-&gt;getId() == 'completed' &amp;&amp; ...) {

  }
}