i have a cart that has three method standard delivery(0-10kg), standard delivery(11-20kg) and next day delivery(0-20kg), my problem is when i a product with a frozen food shipping class to the cart the shipping method should only be the next day delivery and if there is now shipping class on the cart it only has the standard delivery, my problem is when a add the product with a shipping class and a products with no shipping class it will not go to the condition that i make.
add_filter( 'woocommerce_package_rates', 'custom_hide_shipping_methods', 10, 2 );
function custom_hide_shipping_methods( $rates, $package ) {
foreach( WC()->cart->get_cart() as $cart_item ) {
$product = $cart_item[ 'data' ]; // The WC_Product object
if( $product->get_shipping_class_id() == 149 ) { // <== ID OF MY SHIPPING_CLASS
unset( $rates['shipping_by_rules:16'] ); // standard delivery
wc_add_notice( sprintf( __( '1', 'woocommerce' ), $weight ), 'error' );
}else if($product->get_shipping_class_id() == NULL){
unset( $rates['shipping_by_rules:15'] ); // next day delivery
wc_add_notice( sprintf( __( '2', 'woocommerce' ), $weight ), 'error' );
}else if($product->get_shipping_class_id() != || $product->get_shipping_class_id() == 149){
unset( $rates['shipping_by_rules:16'] ); // standard delivery
wc_add_notice( sprintf( __( '3', 'woocommerce' ), $weight ), 'error' );
}
break; // we stop the loop
}
return $rates;
}