Skip to content

Commit

Permalink
[#928] Adjust order results to sort by Subtotal (#930)
Browse files Browse the repository at this point in the history
* [#928] Adjust order results to sort by Subtotal

* [#928] Remove unnecessary loop
  • Loading branch information
bd-viget authored Apr 26, 2024
1 parent f4b629a commit 1b90fdf
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion client-mu-plugins/goodbids/src/classes/Auctions/Auctions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}

/**
Expand Down

0 comments on commit 1b90fdf

Please sign in to comment.