最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

woocommerce - Shipping cost double after split the shipping packages by shipping class - Stack Overflow

programmeradmin2浏览0评论
function bbloomer_split_shipping_packages_by_class( $packages ) {   
   $destination = $packages[0]['destination'];  
   $user = $packages[0]['user']; 
   $applied_coupons = $packages[0]['applied_coupons'];
   $packages = array();
    
   foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {    
      $key = $cart_item['data']->get_shipping_class_id();
      $packages[$key]['contents'][$cart_item_key] = $cart_item;
   }
    
   foreach ( $packages as $index => $package ) {
      $total = array_sum( wp_list_pluck( $packages[$index]['contents'], 'line_total' ) );
      $packages[$index]['destination'] = $destination;
      $packages[$index]['user'] = $user;
      $packages[$index]['applied_coupons'] = $applied_coupons;
      $packages[$index]['contents_cost'] = $total;
   }
 
   return $packages;
 
}

hook "woocommerce_cart_shipping_packages" I have used this function to split the shipping package according to shipping class. but after that when I add two products one from each shipping class then the shipping cost is double means shipping cost * 2. if the shipping cost 10 after adding the second product or third then it increases to 20, please guide me. Thanks in advance. The shipping cost will not double. I have also set a flat rate shipping rate and setting per order

发布评论

评论列表(0)

  1. 暂无评论