I need to get the due date (payment) of the last order, but I got some kind of crooked code.

I receive all user orders by request.

      $allOrders = \Drupal::entityTypeManager()->getStorage('commerce_order')->loadByProperties(
    ['state' => 'completed',
      'uid' => $uid,

I cannot figure out why the following code is not working


The following code worked for me, I think it is wrong and unnecessary.

      $IndexAr = array_key_last($allOrders);
  $oneIndex = $allOrders[$IndexAr];
  $AllValues = $oneIndex->toArray();
  $DataTime = $AllValues["completed"][0]["value"];

Here is the data structure: enter image description here


Your Answer

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

Browse other questions tagged or ask your own question.