Skip to main content
Login Join
Snippet · PHP

Hide All Shipping Methods When Free Shipping Is Available

Shared by Kamran Abdul Aziz · May 13, 2026 · @woocommerce_package_rates

35 views
Back to Snippets

When free shipping becomes available in WooCommerce (via minimum order, coupon, or any other condition), this snippet automatically hides all other shipping methods – such as flat rate and local pickup – leaving only the free shipping option(s) visible to the customer. Unlike threshold-based approaches, this works by detecting the presence of the free_shipping method ID in the available rates, so it responds to any free shipping trigger you have configured. Supports multiple free shipping instances and follows WordPress Coding Standards.

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

function hide_shipping_when_free_is_available( $rates, $package ) {

    $free = array();

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

        if ( 'free_shipping' === $rate->method_id ) {

            $free[ $rate_id ] = $rate;

        }

    }

    return ! empty( $free ) ? $free : $rates;

}
Know a different way to do this? Add your approach as a variation so folks can compare them side by side.
Submit a variation

0 comments