i have a problem:
i have two shipping categories
1- alfa
2- beta
alfa should be 50$ by order (not by products) and if alfa products sum (without shipping and taxes) is more than 400$, alfa shipping is free. i've done that rule, it works correctly only if alfa products and no others are inserted into chart.
beta should use fedEx shipping plugin to calculate, it works correctly only if beta products and no others are inserted into chart.
if i put alfa and beta products into chart i only get the alfa rules.
i set the rules with Tree Table shipping plugin in this way:
USA
Child rules rate add sum of child rates
ALFA
Package all items at once
Contains specified and maybe others ALFA any amount
Calculate fees for all matching items at once
Other shipping plugins FEDEX add all rates
BETA
Contains specified and maybe others BETA subtotal without tax and discount below 400$
Charge Flat Fee 50$
BETA
Contains specified and maybe others BETA subtotal without tax and discount above 400$
Free shipping
Split the cart by shipping class and also select the "Capture" option so subsequent rules are not processed once a shipping class package has been processed. Create child rules and each one should contain their respective shipping class will the "all specified & no others" option so that each rule only applies to their respective shipping class.
Got this snippet from here
add_filter( 'woocommerce_cart_shipping_packages', 'wf_split_cart_by_shipping_class_group' );
function wf_split_cart_by_shipping_class_group($packages){
//Reset packages
$packages = array();
//Init splitted package
$splitted_packages = array();
// Group of shipping class ids
$class_groups = array(
'group1' => array(9,10),
'group2' => array(20),
'group3' => array(11,15,17),
);
// group items by shipping classes
foreach ( WC()->cart->get_cart() as $item_key => $item ) {
if ( $item['data']->needs_shipping() ) {
$belongs_to_class_group = 'none';
$item_ship_class_id = $item['data']->get_shipping_class_id();
if($item_ship_class_id){
foreach($class_groups as $class_group_key => $class_group){
if(in_array($item_ship_class_id, $class_group)){
$belongs_to_class_group = $class_group_key;
continue;
}
}
}
$splitted_packages[$belongs_to_class_group][$item_key] = $item;
}
}
// Add grouped items as packages
if(is_array($splitted_packages)){
foreach($splitted_packages as $splitted_package_items){
$packages[] = array(
'contents' => $splitted_package_items,
'contents_cost' => array_sum( wp_list_pluck( $splitted_package_items, 'line_total' ) ),
'applied_coupons' => WC()->cart->get_applied_coupons(),
'user' => array(
'ID' => get_current_user_id(),
),
'destination' => array(
'country' => WC()->customer->get_shipping_country(),
'state' => WC()->customer->get_shipping_state(),
'postcode' => WC()->customer->get_shipping_postcode(),
'city' => WC()->customer->get_shipping_city(),
'address' => WC()->customer->get_shipping_address(),
'address_2' => WC()->customer->get_shipping_address_2()
)
);
}
}
return $packages;
}