Skip to content

WooCommerce Hide Shipping for Heavy Products Without Plugin

By geekerhub 9 min read

WooCommerce PHP code to hide shipping methods for heavy products

Some WooCommerce stores sell products that are too heavy or too large for their normal shipping services. For example, a store may sell furniture, gym equipment, machinery parts or large home appliances. Standard shipping may not be suitable for these items because of weight limits or delivery costs.

In this situation, you may want to hide certain shipping methods when a cart becomes too heavy. WooCommerce lets you do this with a small PHP snippet, without installing another shipping plugin. In this guide, you will learn how to hide Flat Rate shipping, block multiple shipping methods and restrict shipping when a specific heavy product is in the cart.

What This WooCommerce Code Does

  • Checks the weight of products in a shipping package.
  • Hides selected shipping methods when the weight limit is exceeded.
  • Can block Flat Rate, Free Shipping or Local Pickup.
  • Can check for individual heavy products.
  • Updates the available shipping rates when WooCommerce recalculates them.
  • Works without an additional shipping rules plugin.

Important: Hiding a shipping method does not arrange an alternative delivery service. Make sure your store still offers a suitable shipping option for heavy orders, or clearly explain how customers can arrange delivery.

WooCommerce PHP Snippet to Hide Shipping for Heavy Products

This example hides the Flat Rate shipping method when the total weight of products in the current shipping package exceeds 20 weight units. The weight unit depends on your WooCommerce settings, so check whether your store uses kilograms, grams, pounds or another unit before setting the limit.

/**
 * Hide Flat Rate shipping for heavy packages.
 */

add_filter(
    'woocommerce_package_rates',
    'gh_hide_flat_rate_for_heavy_packages',
    100,
    2
);

function gh_hide_flat_rate_for_heavy_packages( $rates, $package ) {

    // Set the maximum package weight in your store's weight unit.
    $weight_limit = 20;

    $package_weight = 0;

    // Calculate the weight of products in this shipping package.
    if ( ! empty( $package['contents'] ) ) {
        foreach ( $package['contents'] as $item ) {

            if ( empty( $item['data'] ) ) {
                continue;
            }

            $product = $item['data'];

            if ( $product->needs_shipping() && $product->has_weight() ) {
                $package_weight +=
                    (float) $product->get_weight()
                    * (int) $item['quantity'];
            }
        }
    }

    // Hide Flat Rate if package weight exceeds the limit.
    if ( $package_weight > $weight_limit ) {

        foreach ( $rates as $rate_id => $rate ) {

            if ( 'flat_rate' === $rate->method_id ) {
                unset( $rates[ $rate_id ] );
            }
        }
    }

    return $rates;
}

How to Customize the Weight Limit

Find this line in the code:

$weight_limit= 20;

Change 20 to the maximum weight you want to allow for Flat Rate shipping. For example, if your store uses kilograms and your limit is 15 kg, change the value to 15.

The code checks each product’s weight and multiplies it by the quantity in the package. Products without a weight set in WooCommerce will not add to this calculation, so make sure your shippable products have accurate weights.

How the WooCommerce Shipping Filter Works

The snippet uses the woocommerce_package_rates filter. WooCommerce runs this filter when it processes shipping rates for a package. The code checks the package contents and removes the Flat Rate option if the weight is over your limit.

The filter can remove a shipping option, but it does not change the product weight, shipping zone or shipping price. You can read more in the official WooCommerce code reference.

One detail matters here: the code checks the weight of the current shipping package, not necessarily the weight of the entire cart. If another plugin splits an order into several packages, each package is checked separately. This is often more suitable for shipping rules, but it may not match a business rule based on the entire cart weight.

How to Hide Multiple WooCommerce Shipping Methods

You may want to hide more than Flat Rate shipping when an order is heavy. For example, you might block Flat Rate and Free Shipping but keep Local Pickup available.

Use the following complete snippet instead of the first snippet. Do not add both versions together unless you intentionally want to combine their rules.

/**
 * Hide selected shipping methods for heavy packages.
 */

add_filter(
    'woocommerce_package_rates',
    'gh_hide_multiple_methods_for_heavy_packages',
    100,
    2
);

function gh_hide_multiple_methods_for_heavy_packages( $rates, $package ) {

    $weight_limit = 20;

    // Method IDs to hide when the package is too heavy.
    $blocked_methods = array(
        'flat_rate',
        'free_shipping',
    );

    $package_weight = 0;

    if ( ! empty( $package['contents'] ) ) {
        foreach ( $package['contents'] as $item ) {

            if ( empty( $item['data'] ) ) {
                continue;
            }

            $product = $item['data'];

            if ( $product->needs_shipping() && $product->has_weight() ) {
                $package_weight +=
                    (float) $product->get_weight()
                    * (int) $item['quantity'];
            }
        }
    }

    if ( $package_weight > $weight_limit ) {

        foreach ( $rates as $rate_id => $rate ) {

            if ( in_array( $rate->method_id, $blocked_methods, true ) ) {
                unset( $rates[ $rate_id ] );
            }
        }
    }

    return $rates;
}

In this example, both Flat Rate and Free Shipping are removed when the package weight exceeds 20 units. Local Pickup remains available because it is not included in the blocked methods list.

To block Local Pickup as well, add 'local_pickup' to the array. Only use method IDs that match the shipping methods configured in your store.

How to Hide Shipping When a Specific Heavy Product Is in the Cart

Sometimes the total cart weight is not the main concern. You may sell one large product that requires special delivery, even when the rest of the cart is light.

The following example hides Flat Rate shipping if any product in the current shipping package weighs 15 units or more per item. It checks the product’s individual weight, not the weight multiplied by its quantity.

/**
 * Hide Flat Rate if a package contains an individually
 * heavy product.
 */

add_filter(
    'woocommerce_package_rates',
    'gh_hide_flat_rate_for_heavy_items',
    100,
    2
);

function gh_hide_flat_rate_for_heavy_items( $rates, $package ) {

    $heavy_item_limit = 15;
    $has_heavy_item   = false;

    if ( ! empty( $package['contents'] ) ) {
        foreach ( $package['contents'] as $item ) {

            if ( empty( $item['data'] ) ) {
                continue;
            }

            $product = $item['data'];

            if ( ! $product->needs_shipping() || ! $product->has_weight() ) {
                continue;
            }

            if ( (float) $product->get_weight() >= $heavy_item_limit ) {
                $has_heavy_item = true;
                break;
            }
        }
    }

    if ( $has_heavy_item ) {

        foreach ( $rates as $rate_id => $rate ) {

            if ( 'flat_rate' === $rate->method_id ) {
                unset( $rates[ $rate_id ] );
            }
        }
    }

    return $rates;
}

For example, if your limit is 15 kg, a single product weighing 16 kg triggers the restriction even if the rest of the package is light. A product weighing 10 kg does not trigger it on its own.

This rule checks product weight only. If you need to restrict specific products regardless of their weight, use product IDs, shipping classes or product categories instead.

How to Add the Code to WordPress

  1. Back up your website before changing PHP code.
  2. Open your WordPress dashboard.
  3. Use a code snippets tool or open the functions.php file of your child theme.
  4. Copy one complete snippet from this guide.
  5. Paste the code without the surrounding HTML code tags.
  6. Save the snippet and enable it, or save the child theme file.
  7. Test the checkout with light and heavy products.
  8. Check each shipping zone and confirm that the expected shipping methods remain available.

A code snippets tool can make it easier to disable the code if a problem occurs. Avoid editing the parent theme’s functions.php file because theme updates may overwrite your changes.

How to Test the Shipping Restriction

Do not assume the code is working just because the website loads. Test the actual shipping choices shown to customers.

  • Add a light product to the cart and check that Flat Rate appears when it should.
  • Add a product that takes the package over the weight limit and check that Flat Rate disappears.
  • Test quantities, because several light products may exceed the total weight limit.
  • Test a product that individually exceeds the heavy-item limit.
  • Check carts with different delivery addresses and shipping zones.
  • Test the checkout again after changing product quantities or removing items.

WooCommerce may cache calculated shipping rates in the customer session. If the results appear outdated during testing, refresh the cart or recalculate shipping and test again. Shipping extensions can also change how packages and rates are generated.

Common Problems and Things to Check

Shipping Methods Are Not Disappearing

Check that the snippet is enabled, the weight limit uses the correct unit and the product weights are filled in. Also confirm that the shipping method ID is correct. The method ID is not always the same as the displayed shipping method name.

All Shipping Options Disappear

If every available rate is removed, customers may not be able to complete checkout. Keep a suitable alternative, such as an approved freight method or Local Pickup, when your business supports it. If no delivery method is suitable, explain the next step clearly to customers.

The Rule Works for One Package but Not the Whole Cart

WooCommerce and shipping extensions may split cart items into separate packages. The first two snippets check each package independently. If your rule must use the combined weight of the entire cart, the code needs to calculate that total and apply it consistently to every package.

Product Weights Are Missing

A product without a configured weight cannot contribute a meaningful weight to these examples. Review your product data, including variations, and set the correct weights before relying on weight-based shipping rules.

Other Shipping Rules You Can Add

  • Hide Express Shipping for packages above a weight limit.
  • Keep Local Pickup available for heavy products.
  • Use a shipping class for oversized products.
  • Restrict shipping methods for selected product categories.
  • Display a checkout notice explaining that a heavy order needs a different delivery option.
  • Use a freight service for products that cannot be sent through standard shipping.

For complicated rules involving package dimensions, different carriers, postcode restrictions or several shipping conditions, a dedicated shipping rules extension may be easier to maintain than custom code.

Frequently Asked Questions

Can I hide WooCommerce shipping methods without a plugin?
Yes. You can use the woocommerce_package_rates filter in a child theme or a code snippets tool to remove selected shipping rates based on your conditions.

Does the code hide Flat Rate for the entire cart?
The main example checks the weight of each shipping package. If WooCommerce splits the cart into multiple packages, the rule applies to each package separately.

Can I hide Free Shipping for heavy products?
Yes. Add free_shipping to the blocked methods array in the multiple-methods example.

Can I keep Local Pickup available for heavy orders?
Yes. Leave local_pickup out of the blocked methods array so that it is not removed by that snippet.

Does the weight limit use kilograms?
It uses the weight unit configured in WooCommerce. Check your store’s measurement settings and enter the limit in the same unit.

Can I hide shipping based on one product instead of total weight?
Yes. Use the individual heavy-product example to hide Flat Rate when a product reaches the specified weight threshold.

Final Thoughts

WooCommerce can hide shipping methods for heavy packages without an extra plugin. With the woocommerce_package_rates filter, you can check package weight, remove selected shipping methods or apply a restriction when a specific heavy product is present.

Start with one rule, test it carefully and make sure customers still have a valid way to receive their orders. If your store uses split packages or third-party shipping extensions, test those cases before using the code on a live website.