Merge pull request #15578 from woocommerce/fix/15573
Add support for paginate with return ids in wc_order_query
This commit is contained in:
commit
b3c0e705c9
|
@ -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(
|
||||
|
|
|
@ -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.
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue