Product A has been added to the cart and shipping is required. Product B has been added to the cart, and when it is added, shipping should be free. That is, the total price does not necessarily determine whether or not shipping is charged.
However, when added together Woocoomerce will charge for shipping because the shopping cart contains both charged and non-charged products.
I tried this code below, but it didn't work
function wcs_my_free_shipping( $is_available ) {
global $woocommerce.
// set the product ids that are eligible
$eligible = array( '560' );
// get cart contents
$cart_items = $woocommerce->cart->get_cart();
// loop through the items looking for one in the eligible array
foreach ( $cart_items as $key => $item ) {
if( in_array( $item['product_id'], $eligible ) ) {
return true;
}
}
// nothing found return the default value
return $is_available.
}
add_filter( 'woocommerce_shipping_free_shipping_is_available', 'wcs_my_free_shipping', 20 );
Can someone analyze this?