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