title: Woocommerce get orders by product ID with pagination
body: <p>I'm currently able to return woocommerce orders using the wc_get_orders() and WC order query.</p>
  
  <p><a href="https://github.com/woocommerce/woocommerce/wiki/wc_get_orders-and-WC_Order_Query" rel="nofollow noreferrer">https://github.com/woocommerce/woocommerce/wiki/wc_get_orders-and-WC_Order_Query</a></p>
  
  <p>My query for orders is:</p>
  
  <pre><code>$query = new WC_Order_Query( array(
     'paginate' =&gt; true,
     'limit' =&gt; 2,
     'orderby' =&gt; 'date',
     'order' =&gt; 'DESC',
  ) );
  
  $activity = $query-&gt;get_orders();
  </code></pre>
  
  <p>Woocomerce docs link above shows you can query by custom meta.</p>
  
  <pre><code>/**
   * Handle a custom 'customvar' query var to get orders with the 'customvar' meta.
   * @param array $query - Args for WP_Query.
   * @param array $query_vars - Query vars from WC_Order_Query.
   * @return array modified $query
   */
  function handle_custom_query_var( $query, $query_vars ) {
      if ( ! empty( $query_vars['customvar'] ) ) {
          $query['meta_query'][] = array(
              'key' =&gt; 'customvar',
              'value' =&gt; esc_attr( $query_vars['customvar'] ),
          );
      }
  
      return $query;
  }
  add_filter( 'woocommerce_order_data_store_cpt_get_orders_query', 'handle_custom_query_var', 10, 2 );
  </code></pre>
  
  <p>I can't work out how to query by product ID in order to show orders for a specific product and have working pagination.</p>
  
  <p>Once the query has returned orders I am able to get the order product IDs using the get_items() function. But then I can't paginate from the original query correctly.</p>
  
  <p>Is there another method for achieving this? would the using the woocomerce API be a better method or a direct SQL query?</p>
  
  <p>Help would be appreciated.</p>