Guest User

Shipping rate by distance custom snippet

a guest
Sep 5th, 2023
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.50 KB | None | 0 0
  1. add_filter('wpali_distance_shipping_rate', 'wpali_add_base_price_to_rate', 10, 2);
  2. function wpali_add_base_price_to_rate($rate, $obj)
  3. {
  4.     if (!empty($rate['meta_data']['value'])) {
  5.         $meters = $rate['meta_data']['value'];
  6.         $distance_in_km = $meters * 0.001;
  7.         if($distance_in_km > 10 ){
  8.             $rate['cost'] = $rate['cost'] + 29;
  9.         }else{
  10.             $rate['label'] = 'Fixed distance rate';
  11.             $rate['cost'] = 29;
  12.         }
  13.     }
  14.     return $rate;
  15. }
  16.  
  17.  
Advertisement
Add Comment
Please, Sign In to add comment