WC_Cart_Totals::sort_coupons_callback( WC_Coupon $a, WC_Coupon $b )

Sort coupons so discounts apply consistently across installs.


Description Description

In order of priority;

  • sort param
  • usage restriction
  • coupon value
  • ID

Parameters Parameters

$a

(Required) Coupon object.

$b

(Required) Coupon object.


Top ↑

Return Return

(int)


Top ↑

Source Source

File: includes/class-wc-cart-totals.php

	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;
	}

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.