WordPress at Your Fingertips
function is not described

WC_Cart_Totals::sort_coupons_callback() protected WC 1.0

Sort coupons so discounts apply consistently across installs.

In order of priority;

  • sort param
  • usage restriction
  • coupon value
  • ID

{} It's a method of the class: WC_Cart_Totals{}

No Hooks.

Return

Int.

Usage

// protected - for code of main (parent) or child class
$result = $this->sort_coupons_callback( $a, $b );
$a(WC_Coupon) (required)
Coupon object.
$b(WC_Coupon) (required)
Coupon object.

Code of WC_Cart_Totals::sort_coupons_callback() WC 5.9.0

protected function sort_coupons_callback( $a, $b ) {
	if ( $a->sort === $b->sort ) {
		if ( $a->get_limit_usage_to_x_items() === $b->get_limit_usage_to_x_items() ) {
			if ( $a->get_amount() === $b->get_amount() ) {
				return $b->get_id() - $a->get_id();
			}
			return ( $a->get_amount() < $b->get_amount() ) ? -1 : 1;
		}
		return ( $a->get_limit_usage_to_x_items() < $b->get_limit_usage_to_x_items() ) ? -1 : 1;
	}
	return ( $a->sort < $b->sort ) ? -1 : 1;
}