Actually I want to add shipping rates based on region,I added shipping rates like below,
800:40.00,1250:60.00,1700:80.00,2200:100.00,2700:120.00,99999:40.00
If weight is 800 gms it should take 40 and also it should take from 800-1250gms 40 rs but even 1000gms it is taking 60 rs but it shouldn't take how to resolve this?
Use this code to check in range:
function in_range($number, $min, $max)
{
if (is_int($number) && is_int($min) && is_int($max))
{
return ($number >= $min && $number < $max);
}
return FALSE;
}
Also you have create array like this:
$array = array(
[0] => array(
minw : 1,
maxw : 1249,
rate : 40
),
[1] => array(
minw : 1250,
maxw : 1699,
rate : 60
)
);
After that to get rate use this loop function:
$weight = 500;
function get shipping_rate($array, $weight) {
foreach($array as offset => $arr) {
$minw = $arr['minw'];
$maxw = $arr['maxw'];
$rate = $arr['rate'];
if(in_range($weight, $minw, $maxw)) {
return $rate;
}
}
}