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;
}