Product A is added in cart and it has shipping fees. Product B is added in cart and once its added, shipping should be free. However Woocoomerce charges shipping, because Cart includes product with fees and without fees.
I Tried this code 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 );
2
Answers
I used two codes
} add_filter( 'woocommerce_shipping_free_shipping_is_available', 'wcs_my_free_shipping', 20 );
and
} add_filter( 'woocommerce_shipping_free_shipping_is_available', 'wcs_my_free_shipping', 20 );
Try the following code replacement, hiding other shipping methods when free shipping is available:
Code goes in functions.php file of your child theme (or in a plugin). It could work.