← Back to All Snippets

Hide Other Shipping Methods When Free Shipping is Available in WooCommerce

⚡ Target: functions.php 🔒 Tested: WooCommerce 8.0+ / WP 6.6+ 💻 Lang: PHP
PHP (functions.php)
add_filter( 'woocommerce_package_rates', function( $rates, $package ) {
    $free_shipping = [];
    foreach ( $rates as $rate_id => $rate ) {
        if ( 'free_shipping' === $rate->method_id ) {
            $free_shipping[ $rate_id ] = $rate;
            break;
        }
    }
    return ! empty( $free_shipping ) ? $free_shipping : $rates;
}, 10, 2 );

By default, WooCommerce continues to display Flat Rate and Local Pickup alongside Free Shipping. This filter hides paid shipping rates once a customer qualifies for Free Shipping.

← Back to All Snippets Explore Dev Tools →