Get all orders which contains a certain product type In want to print a list of orders:

{% set orders = craft.orders.completed(true).limit(null).all() %}


Now I want to make a list of orders with only the product.type XYZ.

I tried to fabricate something out of this question. But I'd like specific product types:

{% set orders = craft.orders.completed(true).hasPurchasables([type.XYZ]).limit(null).all() %}


This returns:


  Variable "type" does not exist.


How do I have to write this?
You're close. Products themselves aren't Purchasebles. 

However, Variants of products are. And you can have more than one Variant of a Product.

So, we need to get all Variants of a particular Product type and then feed your query:

{# get products of a certain type #}
{% set productIds = craft.products.type('classes').ids() %}

{# get the variants from those product Ids #}
{% set theVariants = craft.variants.productId(productIds).all() %}

{# grab orders #}
{% set orders = craft.orders.completed(true).hasPurchasables(theVariants).limit(null).all() %}


You'll probably want to limit the orders returned at some point depending on how you're displaying or querying them.