You appear to be a bot. Output may be restricted
Description
Picks a selection of rates 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 |
---|
Usage
$- = OIK_Shipping_Pro::pick_rates_for_weight( $rates_array, $weight );
Parameters
- $rates_array
- ( mixed ) required –
- $weight
- ( string ) required – the cart weight
Returns
- rates – array may be empty if no rates are determinedTO DO
Check if this is true e.g.50 | 1.70 | 1 | Second class |
---|---|---|---|
50 | 100.00 | 1 | Knight in shining armour |
77 | X | 1 | Too heavy for this shipping method. |
Source
File name: oik-weightcountry-shipping-pro/class-oik-shipping-pro.phpLines:
1 to 42 of 42
function pick_rates_for_weight( $rates_array, $weight ) { //bw_trace2(); $picked_rates = array(); $max_rate = false; $found_weight = -1; $found = false; $higher_weight = -1; if ( sizeof( $rates_array ) > 0) { $rates = $this->sort_ascending( $rates_array ); //bw_trace2( $rates, "rates" ); foreach ( $rates as $key => $value) { $max_weight = $value[0]; //bw_trace2( "$weight $max_weight $found_weight $higher_weight", "weights:", false ); if ( ( $max_weight > $found_weight ) && ( $max_weight < $weight) && ( !$found ) ) { $found_weight = $max_weight; } if ( $weight <= $max_weight && ( $found_weight <= $weight ) && ( $max_weight <= $higher_weight || !$found ) ) { $picked_rates[] = array( "rate" => $value[1] , "title" => $this->set_countrygroup_title( $value ) ); //bw_trace2( $rate, "rate is now", false ); $found = true; $higher_weight = $max_weight; //bw_trace2( $picked_rates, "picked_rates", false ); } if ( !$found ) { if ( !$max_rate || ( is_numeric( $value[1] ) && $value[1] > $max_rate ) ) { $max_rate = $value[1]; $this->set_countrygroup_title( $value ); } } } } //bw_trace2( $picked_rates, "rates" ); if ( count( $picked_rates ) == 0 && $max_rate ) { $picked_rates[] = array( "rate" => $max_rate , "title" => $this->countrygroup_title ); } return( $picked_rates ); }View on GitHub