title: Wordpress - Woocommerce - Retrieve orders for specific product
body: <p>I am using the woocommerce wordpress plugin and I have retrieved a list of all orders using the WC_Order class. <a href="http://docs.woothemes.com/wc-apidocs/class-WC_Order.html" rel="nofollow">WC_Order documentation</a></p>
  
  <p>This returns simple information about an order like ID, date and status but I need to know the product the customer bought.</p>
  
  <p>So far my working code is:</p>
  
  <pre><code>$args = array(
      'post_type' =&gt; 'shop_order',
      'post_status' =&gt; 'publish',
      'meta_key' =&gt; '_customer_user',
      'posts_per_page' =&gt; '-1'
  );
  
  $my_query = new WP_Query($args);
  $customer_orders = $my_query-&gt;posts;
  
  $all_order_data = array();
  
  foreach ($customer_orders as $customer_order) {
      $order = new WC_Order();
      $order-&gt;populate($customer_order);
      $orderdata = (array) $order;
      $all_order_data[] = $orderdata;
  }
  </code></pre>
  
  <p>For easy viewing of the data I output it as json:</p>
  
  <pre><code>echo json_encode($all_order_data);
  </code></pre>
  
  <p>However, I need to be able to view what product's were purchased with each order. I cannot find a way to do this and I have not seen anything on the web about achieving this functionality. Likewise, if possible, retrieving orders that are attached to a product would be very important for me also.</p>
  
  <p>Has anyone done this before? Or can anyone point me in the right direction?</p>