Sort items for discounts by price. Price includes quantity

When setting up the items array, the item price is the product price * qty,
or order item subtotal and so already accounts for the quantity.
This commit is contained in:
James Allan 2019-12-04 16:38:54 +10:00 committed by Leif Singer
parent 452fa75038
commit fddc63584d
2 changed files with 6 additions and 4 deletions

View File

@ -0,0 +1,4 @@
Significance: patch
Type: fix
Sort items for before applying discounts by the price property

View File

@ -291,12 +291,10 @@ class WC_Discounts {
* @return int
*/
protected function sort_by_price( $a, $b ) {
$price_1 = $a->price * $a->quantity;
$price_2 = $b->price * $b->quantity;
if ( $price_1 === $price_2 ) {
if ( $a->price === $b->price ) {
return 0;
}
return ( $price_1 < $price_2 ) ? 1 : -1;
return ( $a->price < $b->price ) ? 1 : -1;
}
/**