# Hide a Shipping Method Above a Weight

> Removes a light-parcel option, such as letter post or a small flat rate, when the order is heavier than that service allows.

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

## Code

```php
$wpide_weight_limit  = 2;           // Maximum weight in your store's unit.
$wpide_weight_method = 'flat_rate:5'; // Method ID or rate ID to hide.

add_filter( 'woocommerce_package_rates', function ( $rates, $package ) use ( $wpide_weight_limit, $wpide_weight_method ) {
    $weight = 0.0;

    foreach ( (array) $package['contents'] as $item ) {
        $weight += (float) $item['data']->get_weight() * (int) $item['quantity'];
    }

    if ( $weight <= $wpide_weight_limit ) {
        return $rates;
    }

    foreach ( $rates as $id => $rate ) {
        if ( $id === $wpide_weight_method || $rate->get_method_id() === $wpide_weight_method ) {
            unset( $rates[ $id ] );
        }
    }

    return $rates;
}, 20, 2 );
```

## Notes

Use a method ID (flat_rate, free_shipping) to hide every instance or a full rate ID such as flat_rate:5 for one.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Hide a Shipping Method Above a Weight" 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/
