title: Get orders by date and status woocommerce
body: <p>I need get a list of orders in woocommerce passing start date, final date and status.</p>
  
  <p>I tryed use some techniques like described by <a href="http://develop.woothemes.com/woocommerce/2014/08/wc-2-2-order-statuses-plugin-compatibility/" rel="noreferrer">Mike Jolley</a>, and I mixed with <a href="https://stackoverflow.com/questions/15933994/how-to-filter-by-order-status">this</a>. But I have not had success. This return all orders. I´m using the woocommerce version 2.2.10.</p>
  
  <p>Thanks for help.</p>
  
  <p>My code:</p>
  
  <pre><code>public function get_orders(){
          global $json_api;
          $initial_date = $json_api-&gt;query-&gt;para1;
          $final_date = $json_api-&gt;query-&gt;para2;
          $order_id = $json_api-&gt;query-&gt;para3;
          $status_order = $json_api-&gt;query-&gt;para4;
  
          define('GET_ORDERS_FILTER_DATE_FROM', $initial_date );
          define('GET_ORDERS_FILTER_DATE_TO', $final_date );
          add_filter('posts_where', array( __CLASS__, 'get_orders_where_dates_between') );
          $orders = get_posts( array(
              'post_type'   =&gt; 'shop_order',
              'orderby' =&gt; 'post_date',
              'order'     =&gt; 'DESC',
              'post_status' =&gt; array_keys( $status_order )
          ) );
          remove_filter('posts_where', 'order_page_get_orders_where_dates_between');
  
          return $orders;
  }
  
  function get_orders_where_dates_between( $where ){
          global $wpdb;
          if( ! defined('GET_ORDERS_FILTER_DATE_FROM') || ! defined('PARCELWARE_GET_ORDERS_FILTER_DATE_TO') )
              return $where;
  
          $where .= $wpdb-&gt;prepare(" AND post_date &gt;= '%s' ", GET_ORDERS_FILTER_DATE_FROM);
          $where .= $wpdb-&gt;prepare(" AND post_date &lt;= '%s' ", GET_ORDERS_FILTER_DATE_TO);
  
          return $where;
  }
  </code></pre>