Description
Picks the right rate from available rates based on cart weightIf you want to set a weight at which shipping is free then set a rate for the weight at the limit, and another way above the limit to 0 e.g.
| 50 | 100.00 | 1 | Not free up to and including 50 |
|---|---|---|---|
| 1000 | X | 1 | Maximum weight supported is 999 |
Usage
$- = OIK_Shipping::pick_smallest_rate( $rates_array, $weight );Parameters
- $rates_array
- ( mixed ) required –
- $weight
- ( string ) required – the cart weight
Returns
- rate – may be false if no rate can be determinedSource
File name: oik-weightcountry-shipping/oik-weightcountry-shipping.phpLines:
1 to 34 of 34
function pick_smallest_rate( $rates_array, $weight) { $rate = null; $max_rate = false; $found_weight = -1; $found = false; if ( sizeof( $rates_array ) > 0) { $rates = $this->sort_ascending( $rates_array ); //bw_trace2( $rates, "rates" ); foreach ( $rates as $key => $value) { if ( $weight <= $value[0] && ( $found_weight < $weight ) ) { if ( true || null === $rate || $value[1] < $rate ) { $rate = $value[1]; //bw_trace2( $rate, "rate is now", false ); $found_weight = $value[0]; $found = true; $this->set_countrygroup_title( $value ); } } if ( !$found ) { if ( !$max_rate || $value[1] > $max_rate ) { $max_rate = $value[1]; $this->set_countrygroup_title( $value ); } } } } if ( null === $rate ) { $rate = $max_rate; //$rate = false; } return $rate; }View on GitHub View on Trac
Called by
1 to 2 of 2
Invoked by
Calls
1 to 2 of 2
