Merge pull request #15578 from woocommerce/fix/15573

Add support for paginate with return ids in wc_order_query
This commit is contained in:
Claudio Sanches 2017-06-12 18:17:42 -03:00 committed by GitHub
commit b3c0e705c9
2 changed files with 17 additions and 6 deletions

View File

@ -670,12 +670,7 @@ class WC_Order_Data_Store_CPT extends Abstract_WC_Order_Data_Store_CPT implement
public function query( $query_vars ) {
$args = $this->get_wp_query_args( $query_vars );
$query = new WP_Query( $args );
if ( isset( $query_vars['return'] ) && 'ids' === $query_vars['return'] ) {
return $query->posts;
}
$orders = array_filter( array_map( 'wc_get_order', $query->posts ) );
$orders = ( isset( $query_vars['return'] ) && 'ids' === $query_vars['return'] ) ? $query->posts : array_filter( array_map( 'wc_get_order', $query->posts ) );
if ( isset( $query_vars['paginate'] ) && $query_vars['paginate'] ) {
return (object) array(

View File

@ -445,9 +445,25 @@ class WC_Tests_Order_Functions extends WC_Unit_Test_Case {
$orders = wc_get_orders( array( 'paginate' => true ) );
$this->assertEquals( 2, $orders->total );
$this->assertEquals( 2, count( $orders->orders ) );
$this->assertInstanceOf( 'WC_Order', $orders->orders[0] );
$this->assertEquals( 1, $orders->max_num_pages );
}
/**
* Test the paginate parameter with return id for wc_get_orders.
*
* @since 3.1
*/
public function test_wc_get_order_paginate_id_param() {
$order = WC_Helper_order::create_order();
$order->save();
$orders = wc_get_orders( array( 'paginate' => true, 'return' => 'ids' ) );
$this->assertEquals( 1, $orders->total );
$this->assertEquals( 1, $orders->max_num_pages );
$this->assertEquals( $order->get_id(), $orders->orders[0] );
}
/**
* Test the order parameters for wc_get_orders.
*