title: How to display all orders for a single product showing the most recent first? Woocommerce
body: <p>I have a password protected page on the frontend. On that page, I want to display a full list of all purchases associated with a single woocommerce product id.</p>
  
  <p>Option 1:</p>
  
  <p>I've looked through the <a href="https://docs.woocommerce.com/wc-apidocs/index.html" rel="nofollow noreferrer">woocommerce docs</a>, and I found: 
  <a href="https://docs.woocommerce.com/wc-apidocs/class-WC_CLI_Order.html" rel="nofollow noreferrer">WC_CLI_Order</a> and a <code>list_( $args, $assoc_args )</code> function that lists all orders. </p>
  
  <p>Presumably, the orders can be filtered by <code>product id</code></p>
  
  <p>[--=]
  Filter orders based on order property.</p>
  
  <p>Line item fields (numeric array, started with index zero):</p>
  
  <pre><code>line_items.0.product_id
  </code></pre>
  
  <p>Option 2:</p>
  
  <p>I <a href="https://www.skyverge.com/blog/get-all-woocommerce-orders-for-a-customer/" rel="nofollow noreferrer">found this article</a>, but it is based on the customer id.  I've modified the code based on guesses for meta_key and meta_value.</p>
  
  <pre><code>$customer_orders = get_posts( array(
      'numberposts' =&gt; -1,
      'meta_key'    =&gt; '_product',
      'meta_value'  =&gt; get_product_id(),
      'post_type'   =&gt; wc_get_order_types(),
      'post_status' =&gt; array_keys( wc_get_order_statuses() ),
  ) );
  </code></pre>
  
  <p>How do I display all orders for a single product showing the most recent order first?</p>