You appear to be a bot. Output may be restricted
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.
- |100.00| Not free up to and including 50
- |0.00| Free above 50, up to 999
If the weight is above this highest value then the most expensive rate is chosen. This is rather silly logic… but it'll do for the moment. We also set the shipping rate title for the selected rate. 1000 X Maximum weight supported is 999 Usage
$- = OIK_Weight_Zone_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-weight-zone-shipping/class-oik-weight-zone-shipping.php
Lines:1 to 36 of 36function pick_smallest_rate( $rates_array, $weight) { bw_trace2(); $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", false ); 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_shippingrate_title( $value ); } }else { bw_trace2( $value, $weight, false ); } if ( !$found ) { if ( !$max_rate || $value[1] > $max_rate ) { $max_rate = $value[1]; $this->set_shippingrate_title( $value ); } } } } if ( null === $rate ) { $rate = $max_rate; //$rate = false; } return $rate; }View on GitHub View on Trac