diff --git a/includes/data-stores/class-wc-order-data-store-cpt.php b/includes/data-stores/class-wc-order-data-store-cpt.php index bcf52793b1f..65e17c1530c 100644 --- a/includes/data-stores/class-wc-order-data-store-cpt.php +++ b/includes/data-stores/class-wc-order-data-store-cpt.php @@ -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( diff --git a/tests/unit-tests/order/functions.php b/tests/unit-tests/order/functions.php index 68872822fd1..fdf9b41547f 100644 --- a/tests/unit-tests/order/functions.php +++ b/tests/unit-tests/order/functions.php @@ -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. *