admin管理员组文章数量:1024676
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
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
本文标签: woocommerceShipping cost double after split the shipping packages by shipping classStack Overflow
版权声明:本文标题:woocommerce - Shipping cost double after split the shipping packages by shipping class - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745616084a2159299.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论