WC_Discounts::sort_by_price()protectedWC 3.2.0

Sort by price.

Method of the class: WC_Discounts{}

No Hooks.

Return

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() code WC 8.7.0

protected function sort_by_price( $a, $b ) {
	$price_1 = $a->price * $a->quantity;
	$price_2 = $b->price * $b->quantity;
	if ( $price_1 === $price_2 ) {
		return 0;
	}
	return ( $price_1 < $price_2 ) ? 1 : -1;
}