WooCommerce – Hide shipping methods if items of specific Shipping Class is NOT in cart
Below snippet will hide shipping methods if none of the items in the cart belongs to the specific Shipping Class.
Use the array variable
$shipping_classes to define the shipping classes.
Define the services to_hide.
If you are looking for a plugin to do this job, visit ELEX Hide Shipping Methods Plugin. Using this plugin, You can easily hide shipping methods based on various conditions.
If you want to hide all the shipping methods, you can refer this snippet article for reference code.