Hide Payment Methods Based on Shipping Class in the Cart
As you probably know, shipping classes apply to every product individually.
What does it mean for us? It means that we have to loop through all the products in the cart in our code and check their shipping classes using either get_shipping_class()
or get_shipping_class_id()
methods.

Also we have two options here – if any product in the cart has a specific shipping class or if all the products in the cart have the specific shipping class.
How to Find Shipping Class ID?
When I create conditions with shipping classes in my code I usually use get_shipping_class()
method, so I can check against shipping classes slugs, example. Slugs can easily be found in WooCommerce > Settings > Shipping > Shipping Classes.
But what you have to use get_shipping_class_id()
method? Where and how to get a specific shipping class ID then?
First of all – you can inspect the code in your browser and find it there. In order to do that – please open product edit page and find “Product data” metabox. Go to “Shipping” tab and inspect “Shipping class” dropdown element.

Disable Payment Gateway based on Shipping Method
