Thread Starter
ramtm
(@ramtm)
i need to get all orders that belongs to or contain A PRODUCT. ie if product1 is my product name then i need to get all orders in the loop that contain this product . For to get order detail i use the following query
$args = array(
'post_type' => 'shop_order',
'post_status' => 'publish'
);
$loop=new WP_Query($args);
while($loop->have_posts()): $loop->the_post();
$order_id=get_the_ID();
$order = new WC_Order($order_id);
..details i fetched from query ..
endwhile ;
to get item details i can use $order->get_items();
I want to
(1) it is the best method to fetch order details in the loop ?
(2)How to fetch orders that belongs to product1 [where product1 is my product name ] .?
Please help .
WC_Query is not used directly. Continue to use WP_Query
Thread Starter
ramtm
(@ramtm)
ok . Could you please tell me How to create Woocoomerce order query with product name?
i need to get all orders that belongs to or contain A PRODUCT. ie if product1 is my product name then i need to get all orders in the loop that contain this product . For to get order detail i use the following query
$args = array(
'post_type' => 'shop_order',
'post_status' => 'publish'
);
$loop=new WP_Query($args);
while($loop->have_posts()): $loop->the_post();
$order_id=get_the_ID();
$order = new WC_Order($order_id);
..details i fetched from query ..
endwhile ;
to get item details i can use $order->get_items();
I want to
(1) it is the best method to fetch order details in the loop ?
(2)How to fetch orders that belongs to product1 [where product1 is my product name ] .?
Please help .
This is not straightforward because the data spans multiple tables. Get_posts/WP_Query is not suitable.
You would first need to query order line items for the product id, then pass those order ids to get_posts or WP_query.
Thread Starter
ramtm
(@ramtm)
but that’s make too much time to exicute , if i have many orders .
Thread Starter
ramtm
(@ramtm)
please give the sample code .
but that’s make too much time to exicute , if i have many orders
yes it would. But thats the only way to do it right now. We are looking at ways to use custom tables in the future.
I don’t provide customisations/code sorry. Take a look at the core reports classes which do similar things.