<p>Good solution by Luke,</p>

<p>But if you are still looking for a query to filter Orders by statuses, here's a working solution : </p>

<pre><code>{% for pastOrders in craft.commerce.orders.customer(craft.commerce.customer).orderStatus(1).find() %}
    {{order.id}}
    {{order.orderStatus.name}}
{% endfor %}

{% for pendingOrders in craft.commerce.orders.customer(craft.commerce.customer).orderStatus(2).find() %}
    {{order.id}}
    {{order.orderStatus.name}}
{% endfor %}
</code></pre>

<p>Where 1 is the ID of your pasts orders and 2 is the ID of pending order status...</p>

CC BY-SA 3.0
2017-09-12T13:45:24.423Z
2017-09-12T13:45:24.423Z
Vincent Bourdeau
<p>I would run two queries and then you could utilise the <code>completed()</code> parameter:
<a href="https://craftcommerce.com/docs/craft-commerce-orders#completed" rel="nofollow noreferrer">https://craftcommerce.com/docs/craft-commerce-orders#completed</a></p>

<pre><code>{% set pastOrders = craft.commerce.orders.completed(true).relatedTo({targetElement: currentUser, field: 'deliveryGuy'}).find() %}
{% for order in pastOrders %}
   {{order.id}}
   {{order.orderStatus.name}}
{% endfor %}

{% set pendingOrders = craft.commerce.orders.completed(false).relatedTo({targetElement: currentUser, field: 'deliveryGuy'}).find() %}
{% for order in pendingOrders %}
   {{order.id}}
   {{order.orderStatus.name}}
{% endfor %}
</code></pre>

CC BY-SA 3.0
2017-03-16T08:13:29.613Z
2017-03-16T08:13:29.613Z
Luke Clifton
<p>I am creating a custom dashboard for delivery guys where I want to show the order list in two divs. One is Pending Orders and second is History.
Basically I want to filter my order list by order status.
Here is code:</p>

<pre><code>{% set pastOrders = craft.commerce.orders.relatedTo({targetElement: currentUser, field: 'deliveryGuy'}).find() %}
{% for order in pastOrders %}
   {{order.id}}
   {{order.orderStatus.name}}
{% endfor %}
</code></pre>

<plugin-craftcommerce>
Filter order by order status
# Filter order by order status

(Asked by: username_0 on 2017-03-16)

I am creating a custom dashboard for delivery guys where I want to show the order list in two divs. One is Pending Orders and second is History.
Basically I want to filter my order list by order status.
Here is code:
{% set pastOrders = craft.commerce.orders.relatedTo({targetElement: currentUser, field: 'deliveryGuy'}).find() %}
{% for order in pastOrders %}
   {{order.id}}
   {{order.orderStatus.name}}
{% endfor %}

**Tags:** plugin-craftcommerce


---

## 2 answers

### Answer by username_2 on 2017-03-16. Score: 4 | Accepted answer

I would run two queries and then you could utilise the completed() parameter:
https://craftcommerce.com/docs/craft-commerce-orders#completed
{% set pastOrders = craft.commerce.orders.completed(true).relatedTo({targetElement: currentUser, field: 'deliveryGuy'}).find() %}
{% for order in pastOrders %}
   {{order.id}}
   {{order.orderStatus.name}}
{% endfor %}

{% set pendingOrders = craft.commerce.orders.completed(false).relatedTo({targetElement: currentUser, field: 'deliveryGuy'}).find() %}
{% for order in pendingOrders %}
   {{order.id}}
   {{order.orderStatus.name}}
{% endfor %}


---

### Answer by username_1 on 2017-09-12. Score: 1

Good solution by Luke,
But if you are still looking for a query to filter Orders by statuses, here's a working solution : 
{% for pastOrders in craft.commerce.orders.customer(craft.commerce.customer).orderStatus(1).find() %}
    {{order.id}}
    {{order.orderStatus.name}}
{% endfor %}

{% for pendingOrders in craft.commerce.orders.customer(craft.commerce.customer).orderStatus(2).find() %}
    {{order.id}}
    {{order.orderStatus.name}}
{% endfor %}

Where 1 is the ID of your pasts orders and 2 is the ID of pending order status...


---

