diff --git a/client-mu-plugins/goodbids/src/classes/Auctions/Auctions.php b/client-mu-plugins/goodbids/src/classes/Auctions/Auctions.php index 447e3621..2d92af06 100644 --- a/client-mu-plugins/goodbids/src/classes/Auctions/Auctions.php +++ b/client-mu-plugins/goodbids/src/classes/Auctions/Auctions.php @@ -561,7 +561,39 @@ public function get_bid_order_ids( ?int $auction_id = null, int $limit = -1, ?in ]; } - return wc_get_orders( $args ); + $orders = wc_get_orders( $args ); + + if ( ! $orders || ! is_array( $orders ) ) { + return []; + } + + if ( count( $orders ) <= 1 ) { + return $orders; + } + + return $this->sort_orders_by_subtotal( $orders ); + } + + /** + * Sort Orders by Subtotal + * + * @since 1.0.1 + * + * @param array $orders + * + * @return int[] + */ + private function sort_orders_by_subtotal( array $orders ): array { + $totals = []; + + foreach ( $orders as $order_id ) { + $order = wc_get_order( $order_id ); + $totals[ $order_id ] = $order->get_subtotal(); + } + + arsort( $totals ); + + return array_keys( $totals ); } /**