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

function bbloomer_split_shipping_packages_by_class( $packages ) { $destination = $packages[0]['de

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745616085a4636244.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信