Using Hide shipping method for specific shipping classes in woocommerce answer code, I'm trying to hide shipping options based on shipping class.
Large items and small items have their own shipping class on our website and we only want to offer express shipping on small items.
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 class to find
$class = 92;
// HERE define the shipping method to hide
$method_key_id = 'flat_rate:7';
// Checking in cart items
foreach( WC()->cart->get_cart() as $cart_item ){
// If we find the shipping class
if( $cart_item['data']->get_shipping_class_id() == $class ){
unset($rates[$method_key_id]); // Remove the targeted method
break; // Stop the loop
}
}
return $rates;
}
I understand how to implement the code, however I don't know where to find the shipping class id, I can only find the slug and shipping class name
// HERE define your shipping class to find
$class = 92;
in the above example, where do I find the Id to replace the 92?
Thanks In advance.
Will