WC_Discounts::sort_by_price
Sort by price.
Method of the class: WC_Discounts{}
No Hooks.
Returns
Int.
Usage
// protected - for code of main (parent) or child class $result = $this->sort_by_price( $a, $b );
- $a(array) (required)
- First element.
- $b(array) (required)
- Second element.
Changelog
| Since 3.2.0 | Introduced. |
WC_Discounts::sort_by_price() WC Discounts::sort by price code WC 10.5.0
protected function sort_by_price( $a, $b ) {
$price_1 = $a->quantity > 1 ? $a->price / $a->quantity : $a->price;
$price_2 = $b->quantity > 1 ? $b->price / $b->quantity : $b->price;
if ( $price_1 === $price_2 ) {
return 0;
}
return ( $price_1 < $price_2 ) ? 1 : -1;
}