Hi 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 ] .?
Is anyone know ,Please help .