Advertisement
businessdad

Ticket 5047 - Fix shipping conversion

Apr 27th, 2017
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.65 KB | None | 0 0
  1.     public static function updateShipping($rates, $package) {
  2.         $products=$package['contents'];
  3.         $product=reset($products);
  4.         $total=$package['contents_cost'];
  5.         $total_brixen = $total*1.25;  /**** BRIXEN - INFO: To get total incl. tax (25%) when comparing with Free Shipping minimum amount (this amount is incl. tax, so total has to be incl. tax also) *****/
  6.        
  7.         $shipping=ThemexShop::getShipping(ThemexUser::getShop($product['data']->post->post_author));
  8.        
  9.         $country='';
  10.         if(isset($package['destination']) && isset($package['destination']['country'])) {
  11.             $country=$package['destination']['country'];
  12.         }
  13.        
  14.         if(!empty($rates)) {
  15.             foreach($rates as $key => $rate) {
  16.                 if(isset($shipping[$key]) && !empty($shipping[$key])) {
  17.                     $method=$shipping[$key];
  18.                     $enabled=themex_value('enabled', $method);
  19.                     $available=themex_value('availability', $method);
  20.                     //$amount=themex_value('min_amount', $method); // BRIXEN / ENIITO
  21.                    
  22.                     // Convert the amount from base currency to the active currency
  23.                     // @author Aelia
  24.                     $amount = aelia_convert_to_currency(themex_value('min_amount', $method));
  25.                    
  26.                     $countries=themex_array('countries', $method, array());
  27.                        
  28.  
  29.                     //if($enabled=='no' || (!empty($amount) && $total<$amount) || ($available=='specific' && !in_array($country, $countries))) {
  30.                     if($enabled=='no' || (!empty($amount) && $total_brixen<$amount) || ($available=='specific' && !in_array($country, $countries))) {   //****** BRIXEN */
  31.                        /** echo '<script type="text/javascript">alert("amount: '.$amount.'");</script>'; **/
  32.                         unset($rates[$key]);
  33.                     } else if($key=='flat_rate') {
  34.                         $default=round(floatval(themex_value('default_cost', $method)), 2);
  35.                         $costs=themex_array('costs', $method);
  36.  
  37.                         $cost=$default;
  38.  
  39.                         $rates[$key]->cost=$cost;
  40.                     } else if($key=='international_delivery') {
  41.                         if(($available=='including' && !in_array($country, $countries)) || ($available=='excluding' && in_array($country, $countries))) {
  42.                             unset($rates[$key]);
  43.                         } else {
  44.                             $default=round(floatval(themex_value('cost', $method)), 2);
  45.                             $rates[$key]->cost=$default;
  46.                         }
  47.                     } else if($key=='local_delivery') {
  48.                         $default=round(floatval(themex_value('cost', $method)), 2);
  49.                         $rates[$key]->cost=$default;
  50.                     }
  51.                 }
  52.             }
  53.         }
  54.  
  55.         return $rates;
  56.     }
  57.    
  58. function aelia_convert_to_currency($price, $to_currency = null, $from_currency = null) {
  59.     // If source currency is not specified, take the shop's base currency as a default
  60.     if(empty($from_currency)) {
  61.         $from_currency = get_option('woocommerce_currency');
  62.     }
  63.     // If target currency is not specified, take the active currency as a default.
  64.     // The Currency Switcher sets this currency automatically, based on the context. Other
  65.     // plugins can also override it, based on their own custom criteria, by implementing
  66.     // a filter for the "woocommerce_currency" hook.
  67.     //
  68.     // For example, a subscription plugin may decide that the active currency is the one
  69.     // taken from a previous subscription, because it's processing a renewal, and such
  70.     // renewal should keep the original prices, in the original currency.
  71.     if(empty($to_currency)) {
  72.         $to_currency = get_woocommerce_currency();
  73.     }
  74.  
  75.     // Call the currency conversion filter. Using a filter allows for loose coupling. If the
  76.     // Aelia Currency Switcher is not installed, the filter call will return the original
  77.     // amount, without any conversion being performed. Your plugin won't even need to know if
  78.     // the multi-currency plugin is installed or active
  79.     return apply_filters('wc_aelia_cs_convert', $price, $from_currency, $to_currency);
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement