In the Woocommerce API I see a method wc_get_orders
In the mentioned args I do not see an argument in which I could provide a product ID or Object to limit order results only for that specific product.
Is there a way I could filter orders only for specific products?
I need to use this method since some arguments are necessary
Edited This function doesn't exist, but it can be built. So the function below will return an array of all orders IDs for a given product ID, making the right SQL query:
USAGE 1 (for a given product ID
37
and default Completed orders status):USAGE 2 (for a given product ID
37
and some defined orders statuses):Code goes in function.php file of your active child theme (or theme) or also in any plugin file.
This code is tested and works.
So I wanted to fetch orders specific to a product and a person. I used the solution provided by @LoicTheActec with the wc_get_orders woocommerce method to get the result I want.
Here are the functions:
To filter out the results I want. Since the method does not provide an include argument I had to grab all the orders and then remove the order for the given product id and exclude all the remaining from wc_get_orders: