Great question — answering as the UphillTech team:
To use multiple shipping classes, you should first defined them in an array and in the IF statement you will use in_array() conditional function this way: add_filter( 'woocommerce_package_rates', 'hide_shipping_method_based_on_shipping_class', 10, 2 ); function hide_shipping_method_based_on_shipping_class( $rates, $package ) { if ( is_admin() && ! defined( 'DOING_AJAX' ) ) return; // HERE define your shipping classes to find $classes = [3031, 3032]; // HERE define the shipping methods you want to hide $method_key_ids = array('flat_rate:189'); // Checking in cart items foreach( $package['contents'] as $item ) { // If we find one of the shipping classes if( in_array(...
Full answer by LoicTheAztec: https://stackoverflow.stackexchange.com/a/56407287 (CC BY-SA 4.0).
Need it done for your business? UphillTech.