WordPress at Your Fingertips
function is not described

WC_Tax::sort_rates_callback() private WC 1.0

Does the sort comparison. Compares (in this order):

  • Priority
  • Country
  • State
  • Number of postcodes
  • Number of cities
  • ID

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

No Hooks.

Return

Int.

Usage

$result = WC_Tax::sort_rates_callback( $rate1, $rate2 );
$rate1(object) (required)
First rate to compare.
$rate2(object) (required)
Second rate to compare.

Code of WC_Tax::sort_rates_callback() WC 5.9.0

private static function sort_rates_callback( $rate1, $rate2 ) {
	if ( $rate1->tax_rate_priority !== $rate2->tax_rate_priority ) {
		return $rate1->tax_rate_priority < $rate2->tax_rate_priority ? -1 : 1; // ASC.
	}

	if ( $rate1->tax_rate_country !== $rate2->tax_rate_country ) {
		if ( '' === $rate1->tax_rate_country ) {
			return 1;
		}
		if ( '' === $rate2->tax_rate_country ) {
			return -1;
		}
		return strcmp( $rate1->tax_rate_country, $rate2->tax_rate_country ) > 0 ? 1 : -1;
	}

	if ( $rate1->tax_rate_state !== $rate2->tax_rate_state ) {
		if ( '' === $rate1->tax_rate_state ) {
			return 1;
		}
		if ( '' === $rate2->tax_rate_state ) {
			return -1;
		}
		return strcmp( $rate1->tax_rate_state, $rate2->tax_rate_state ) > 0 ? 1 : -1;
	}

	if ( isset( $rate1->postcode_count, $rate2->postcode_count ) && $rate1->postcode_count !== $rate2->postcode_count ) {
		return $rate1->postcode_count < $rate2->postcode_count ? 1 : -1;
	}

	if ( isset( $rate1->city_count, $rate2->city_count ) && $rate1->city_count !== $rate2->city_count ) {
		return $rate1->city_count < $rate2->city_count ? 1 : -1;
	}

	return $rate1->tax_rate_id < $rate2->tax_rate_id ? -1 : 1;
}