<p>Use the <code>hasPurchasable</code> order query param:</p>

<p><a href="https://docs.craftcms.com/commerce/v2/dev/element-queries/order-queries.html#haspurchasables" rel="nofollow noreferrer">https://docs.craftcms.com/commerce/v2/dev/element-queries/order-queries.html#haspurchasables</a></p>

<pre><code>{% set myOrderQuery = craft.orders()
    .hasPurchasables(product.defaultVariant)
    .limit(10)
%}
</code></pre>

CC BY-SA 4.0
2019-06-24T10:28:18.480Z
Just what I needed, that's working. Thanks Luke
Tim Print
CC BY-SA 4.0
2019-06-22T10:15:13.440Z
2019-06-23T03:21:53.780Z
2019-06-23T03:21:53.780Z
Luke Holder
<p>I'm trying to show some Commerce 2 order information on the front-end. I can't work out the correct syntax. I'm trying to list orders that include a specific product.</p>

<p>I have orders for item SKU "abc123" but this is returning no results.</p>

<pre><code>{% set myOrderQuery = craft.orders()
    .relatedTo("abc123")
    .limit(10)
    %}

{% set orders = myOrderQuery.all() %}

{% if orders|length %}
  &lt;ul&gt;
    {% for order in orders %}
      {% for item in order.lineItems %}
        &lt;li&gt;{{ item.sku }}&lt;/li&gt;
      {% endfor %}
    {% endfor %}
  &lt;/ul&gt;
{% else %}
  &lt;p&gt;No results&lt;/p&gt;
{% endif %}
</code></pre>

<p>If I remove the .relatedTo parameter I get results including orders for that item. How do I just return orders that include that item?</p>

<p>I've tried various permutations of <code>relatedTo</code> and search but haven't found anything that works yet.</p>

<plugin-craftcommerce><search><relatedto>
Searching for item SKU in Commerce orders
# Searching for item SKU in Commerce orders

(Asked by: username_0 on 2019-06-20)

I'm trying to show some Commerce 2 order information on the front-end. I can't work out the correct syntax. I'm trying to list orders that include a specific product.
I have orders for item SKU "abc123" but this is returning no results.
{% set myOrderQuery = craft.orders()
    .relatedTo("abc123")
    .limit(10)
    %}

{% set orders = myOrderQuery.all() %}

{% if orders|length %}
  
    {% for order in orders %}
      {% for item in order.lineItems %}
        {{ item.sku }}
      {% endfor %}
    {% endfor %}
  
{% else %}
  No results
{% endif %}

If I remove the .relatedTo parameter I get results including orders for that item. How do I just return orders that include that item?
I've tried various permutations of relatedTo and search but haven't found anything that works yet.

**Tags:** plugin-craftcommerce, search, relatedto


---

## 1 answers

### Answer by username_1 on 2019-06-22. Score: 2 | Accepted answer

Use the hasPurchasable order query param:
https://docs.craftcms.com/commerce/v2/dev/element-queries/order-queries.html#haspurchasables
{% set myOrderQuery = craft.orders()
    .hasPurchasables(product.defaultVariant)
    .limit(10)
%}

> **Comments:**
> **username_0**: Just what I needed, that's working. Thanks Luke  

---

