Ordering in place
This commit is contained in:
parent
7328bd4a18
commit
a259256550
File diff suppressed because one or more lines are too long
|
@ -2055,7 +2055,13 @@ table.wc_input_table {
|
||||||
padding: 5px 10px;
|
padding: 5px 10px;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
border: 0;
|
border: 0;
|
||||||
|
outline: 0;
|
||||||
background: transparent none;
|
background: transparent none;
|
||||||
|
|
||||||
|
&:focus {
|
||||||
|
outline: 0;
|
||||||
|
box-shadow: none;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
&.compound,
|
&.compound,
|
||||||
|
|
|
@ -266,19 +266,48 @@ class WC_Tax {
|
||||||
return $shipping_rates;
|
return $shipping_rates;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Does the sort comparison.
|
||||||
|
*/
|
||||||
|
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
|
||||||
|
} elseif ( $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;
|
||||||
|
} elseif ( $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;
|
||||||
|
} else {
|
||||||
|
return $rate1->tax_rate_id < $rate2->tax_rate_id ? -1 : 1; // Identical - use ID
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Logical sort order for tax rates based on the following in order of priority:
|
* Logical sort order for tax rates based on the following in order of priority:
|
||||||
* - Priority
|
* - Priority
|
||||||
* - County code
|
* - County code
|
||||||
* - State code
|
* - State code
|
||||||
* - # of zip codes
|
|
||||||
* - # of cities
|
|
||||||
* @param array $rates
|
* @param array $rates
|
||||||
* @return array
|
* @return array
|
||||||
* @todo remove tax_rate_order column
|
* @todo remove tax_rate_order column
|
||||||
*/
|
*/
|
||||||
private static function sort_rates( $rates ) {
|
private static function sort_rates( $rates ) {
|
||||||
|
uasort( $rates, __CLASS__ . '::sort_rates_callback' );
|
||||||
|
$i = 0;
|
||||||
|
foreach ( $rates as $key => $rate ) {
|
||||||
|
$rates[ $key ]->tax_rate_order = $i++;
|
||||||
|
}
|
||||||
return $rates;
|
return $rates;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue