# Hide Other Shipping Rates When Free Shipping Is Available

> When the cart qualifies for free shipping, shows only the free shipping and local pickup options instead of all rates.

- Type: PHP
- Runs: Run everywhere
- Category: [WooCommerce](https://wpide.com/library/category/woocommerce/)
- Requires: WooCommerce
- Tags: woocommerce, shipping, free-shipping
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/woo-hide-shipping-when-free/

## Code

```php
add_filter( 'woocommerce_package_rates', function ( $rates ) {
    $kept = array();

    foreach ( $rates as $rate_id => $rate ) {
        if ( 'free_shipping' === $rate->get_method_id() ) {
            $kept[ $rate_id ] = $rate;
        }
    }

    if ( ! $kept ) {
        return $rates;
    }

    foreach ( $rates as $rate_id => $rate ) {
        if ( in_array( $rate->get_method_id(), array( 'local_pickup', 'pickup_location' ), true ) ) {
            $kept[ $rate_id ] = $rate;
        }
    }

    return $kept;
}, 100 );
```

## Notes

Clear the shipping cache (WooCommerce > Status > Tools) or update the cart to see the change.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Hide Other Shipping Rates When Free Shipping Is Available" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
