To hide a shipping method for specific products in WooCommerce, remove its rate in the woocommerce_package_rates filter when the cart contains one of those products. The filter runs on the server, so it works on the Cart and Checkout blocks as well as the classic checkout. One thing catches almost everyone while testing: WooCommerce caches shipping rates per cart, so after you add or change the code, an existing cart keeps showing the old options. Test with a new cart, or turn on shipping debug mode.
Below is code for product categories and for product IDs, tested on WooCommerce 11.3 with a $10 mug and a $400 "bulky" sofa.
The code: hide free shipping for a product category
The most common case: bulky or heavy items can't ship for free. This hides Free shipping whenever the cart contains a product in the bulky category:
<?php
/**
* Hide shipping methods when the cart contains products from certain categories.
* Shipping method IDs: flat_rate, free_shipping, local_pickup, pickup_location (block Local pickup), or a plugin's ID.
*/
add_filter(
'woocommerce_package_rates',
function ( array $rates, array $package ) {
$categories = array( 'bulky' ); // Product category slugs.
$hide = array( 'free_shipping' ); // Shipping methods to hide for them.
$has_match = false;
foreach ( $package['contents'] as $item ) {
if ( has_term( $categories, 'product_cat', $item['product_id'] ) ) {
$has_match = true;
break;
}
}
if ( ! $has_match ) {
return $rates;
}
foreach ( $rates as $rate_id => $rate ) {
if ( in_array( $rate->get_method_id(), $hide, true ) ) {
unset( $rates[ $rate_id ] );
}
}
return $rates;
},
10,
2
);
What I tested, with a US shipping zone offering Flat rate, Free shipping and Local pickup:
| Cart | Shipping options offered |
|---|---|
| Mug only | Flat rate, Free shipping, Local pickup |
| Mug + bulky sofa | Flat rate, Local pickup |
And on the Checkout block:

How it works:
woocommerce_package_ratesreceives the rates WooCommerce calculated for each shipping package (usually one per cart), keyed by rate ID such asfree_shipping:2.$rate->get_method_id()returns the method type without the instance number (free_shipping), so the code works for every zone. To hide only one zone's method, compare the full rate ID ($rate_id) instead.$item['product_id']is the parent product, also for variations, so a category set on the parent product applies to all its variations.
Hide shipping methods for specific product IDs
Swap the category check for a list of product IDs. This version hides both Free shipping and Local pickup when product 28 is in the cart:
$product_ids = array( 28 ); // Product IDs (for variations, the parent product ID).
$hide = array( 'free_shipping', 'local_pickup' ); // Shipping methods to hide for them.
// …inside the same loop:
if ( in_array( $item['product_id'], $product_ids, true ) ) {
In my test, the mug alone still got all three options, and mug + product 28 got only Flat rate.
To match one variation only, compare $item['variation_id'] instead of $item['product_id'].
The trap: shipping rates are cached
I tested what happens when the code changes while a customer already has a cart. With the snippet active, the bulky cart showed Flat rate and Local pickup. Then I deactivated the snippet, and the same cart still showed Flat rate and Local pickup, with no Free shipping. WooCommerce stores each cart's calculated rates in the customer session and only recalculates when the cart, the address or the shipping settings change.
So when you add or edit shipping code:
- Test with a new cart: a private window, or empty the cart and add the products again.
- Or turn on shipping debug mode: WooCommerce → Settings → Shipping → Shipping settings → Debug mode ("Enable shipping debug mode to show matching shipping zones and to bypass shipping rate cache"). Turn it off again afterwards.
Customers who already have the product in their cart get the new rules once they change the cart or their address.
Shipping classes: the no-code option
If you only need different costs, not hidden methods, WooCommerce's built-in shipping classes may be enough. Give bulky products a "Bulky" shipping class (in the product's Shipping tab), then set a higher cost for that class in the Flat rate settings of each zone. That changes the price but doesn't remove Free shipping, which is why stores use the code above when free shipping must not apply.
To hide a method based on a shipping class instead of a category, check $item['data']->get_shipping_class() in the loop. It returns the class slug, for example bulky.
The opposite case: hide paid rates when free shipping applies
If what you want is to hide the paid methods once an order qualifies for free shipping, you don't need code. WooCommerce has a setting for it: WooCommerce → Settings → Shipping → Shipping settings → "Hide shipping rates when free shipping is available". Don't turn it on together with the code above: WooCommerce applies the setting before the woocommerce_package_rates filter runs, so a bulky cart that qualifies for free shipping first loses Flat rate, then the code removes Free shipping, and only Local pickup (or no method at all) is left.
Where to put the code
Use a code snippets plugin (WPCode, Code Snippets) or a small custom plugin in wp-content/plugins/. Don't use your theme's functions.php, which a theme update or switch would remove.
Common mistakes
- Testing with an old cart. Rates are cached; see above. This causes most "the code doesn't work" reports.
- Comparing rate IDs with the instance number.
free_shipping:2only matches one zone. Useget_method_id()to match the method everywhere. - Hiding every method. If the code removes all rates, customers have no shipping option to choose and can't check out. Always leave at least one method.
- Checking the variation's category. Variations don't have their own categories. Check
$item['product_id'], the parent. - Using
woocommerce_available_payment_gatewaysfor shipping. That filter is for payment methods. For shipping, it'swoocommerce_package_rates.
FAQ
How do I hide free shipping for certain products in WooCommerce?
Remove the free_shipping rate in the woocommerce_package_rates filter when the cart contains those products, as in the code above. Then test with a new cart, because WooCommerce caches rates per cart.
Does woocommerce_package_rates work with the Checkout block?
Yes. The block checkout gets its shipping rates from the server through the Store API, and the filter runs there. In my test on WooCommerce 11.3, the Checkout block offered exactly the rates the filter returned.
Why does my hide shipping code not work?
Most often because the cart's shipping rates are cached. Test in a new cart or private window, or turn on shipping debug mode in WooCommerce → Settings → Shipping. Also check that you compare the method ID (free_shipping) and not a rate ID from another zone.
Can I hide a shipping method for a product category without a plugin?
Yes. The code in this guide does exactly that, using has_term() with the category slug. A shipping class with a higher cost changes prices without code, but it doesn't hide methods.
How do I hide other shipping methods when free shipping is available?
Use the built-in setting: WooCommerce → Settings → Shipping → Shipping settings → "Hide shipping rates when free shipping is available". No code is needed for that case.
How do I find a shipping method's ID?
Built-in methods are flat_rate, free_shipping and local_pickup. The block checkout's own Local pickup option (pickup locations) uses pickup_location. For a plugin's method, temporarily log $rate->get_method_id() inside the filter, or check the value of the shipping option's radio button on the classic checkout (it shows the full rate ID, such as flat_rate:1).
When to get help
If your shipping rules depend on weight, zones, product combinations or a carrier plugin, I can build and test them on a staging copy. See WooCommerce development. Related: hide a payment method for specific products, which works the same way for payment gateways.




