Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_filter('wpali_distance_shipping_rate', 'wpali_add_base_price_to_rate', 10, 2);
- function wpali_add_base_price_to_rate($rate, $obj)
- {
- if (!empty($rate['meta_data']['value'])) {
- $meters = $rate['meta_data']['value'];
- $distance_in_km = $meters * 0.001;
- $distance_in_km = round($distance, 2);
- if($distance_in_km > 10 ){
- $price_per_km = $rate['cost'] / $distance_in_km;
- $cost_per_first_10km = 29;
- $cost_per_remaining_kms = ( $distance_in_km - 10 ) * $price_per_km;
- $rate['cost'] = $cost_per_first_10km + $cost_per_remaining_kms;
- }else{
- $rate['label'] = 'Fixed distance rate';
- $rate['cost'] = 29;
- }
- }
- return $rate;
- }
Advertisement
Add Comment
Please, Sign In to add comment