How do I programmatically load an order by its properties? I know how to load an order by its ID using \Drupal\commerce_order\Entity\Order::load($order_id). I added a custom field (Token ID) to the orders.

How can I load the orders knowing the value of that field? If I want to get the state of the order, how can I achieve it?
The best way to do this is by using by loadByProperties based on Token field:

$orders = \Drupal::entityTypeManager()
  -&gt;getStorage('commerce_order')
  -&gt;loadByProperties(['field_token_id' =&gt; 'TOKEN VALUE']);
$order = reset($orders);
$state = $order-&gt;get('state')-&gt;value;
$total_price = $order-&gt;getTotalprice()-&gt;getNumber();
$currency = $order-&gt;getTotalprice()-&gt;getCurrencyCode();


Here assuming token as a unique value.