Hey there,
you need to set up two shipping calles, and one has to be free shipping. Assign the shipping classes to teach prodcut
WC-_>Shipping classes
than define flat rates per classes
go to WC–>settings–>shipping–>flatrates
then finaly add this to your theme functions.php
add_filter( 'woocommerce_cart_shipping_packages', 'bulky_woocommerce_cart_shipping_packages' );
function bulky_woocommerce_cart_shipping_packages( $packages ) {
// Reset the packages
$packages = array();
// Bulky items
$bulky_items = array();
$regular_items = array();
// Sort bulky from regular
foreach ( WC()->cart->get_cart() as $item ) {
if ( $item['data']->needs_shipping() ) {
if ( $item['data']->get_shipping_class() == 'free' ) {
$bulky_items[] = $item;
} else {
$regular_items[] = $item;
}
}
}
// Put inside packages
if ( $bulky_items ) {
$packages[] = array(
'ship_via' => array( 'flat_rate' ),
'contents' => $bulky_items,
'contents_cost' => array_sum( wp_list_pluck( $bulky_items, 'line_total' ) ),
'applied_coupons' => WC()->cart->applied_coupons,
'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()
)
);
}
if ( $regular_items ) {
$packages[] = array(
'contents' => $regular_items,
'contents_cost' => array_sum( wp_list_pluck( $regular_items, 'line_total' ) ),
'applied_coupons' => WC()->cart->applied_coupons,
'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;
}
-
This reply was modified 5 years, 6 months ago by braehler.