WC_Cart_Totals::sort_coupons_callback()
Sort coupons so discounts apply consistently across installs.
In order of priority;
- sort param
- usage restriction
- coupon value
- ID
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 );
WC_Cart_Totals::sort_coupons_callback() WC Cart Totals::sort coupons callback code WC 9.6.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; }