I am looking forward on how to hide shipping at all from the checkout page of Woocommerce when only certain product (magazine) is in the cart or much better would be, if the only product/s with certain shipping class are in the cart.
If there is a combination of products (magazine + books), then shipping module should be visible.
This is what I have tried, but this always returns false. Can you help me out on this?
add_filter( 'woocommerce_package_rates', 'woocommerce_cart_shipping_total_filter_callback', 11, 2 );
function woocommerce_cart_shipping_total_filter_callback( $show_abon_shipping) {
$product_id = 27733;
$in_cart = false;
foreach( WC()->cart->get_cart() as $cart_item ) {
$product_in_cart = $cart_item['product_id'];
if ( $product_in_cart === $product_id && count($product_in_cart) == 1) {
$in_cart = true;
}
}
if ( $in_cart ) {
return false;
}
return $show_abon_shipping;
}