How to Exclude Shipping Classes from Free Shipping in WooCommerce
Let’s say we have a webshop selling accessories that can be shipped in ordinary parcels. You want to ship those for free when the order exceeds 100€. This is classic free shipping per minimum order value.
Now we decide to sell furniture as well with said webshop. Furniture has to be shipped differently ~ per trucking company ~ and should be excluded from free shipping. Here is what we do.
As bulk shipping is calculated depending on size or weight, whichever turns out to cost more, it would be wise to not get into the complicated details and just create shipping classes for bulky goods roughly representing the costs. When shipping that giant wardrobe we want a shipping class with a slug ‘bulk-giant-wardrobes’ to then put costs to it depending on shipping zones. Here is what we need to add to our functions.php then.
WooCommerce is providing a hook (woocommerce_shipping_free_shipping_is_available) ~ an attachment point for our own logic ~ in the process of figuring out if free shipping should be available to the shopping cart or not.
We run $is_available through our own function after WooCommerce has decided if it should be true or false. We then cycle through all items in the shopping cart looking for a specific shipping class. When a shipping class slug starting with ‘bulk’ is found, we exit our function returning false, and the giant wardrobe is not available for free shipping anymore.