snippet 1 min read PHP 7.4+ WP 5.0+ WC 3.0+
Disable Flat Rate When Free Shipping Is Available in WooCommerce
Hide WooCommerce flat-rate methods whenever a free-shipping method is available in the current package.
Updated Dec 1, 2025 #woocommerce #wordpress #php #shipping #snippet
When free shipping is available, showing a paid flat-rate option can create unnecessary friction at checkout. This filter removes flat-rate methods from the package once WooCommerce has calculated at least one free_shipping rate.
Add it to a child theme’s functions.php file or use a code snippet plugin.
The snippet
// Disable Flat Rate if Free Shipping is available.add_filter( 'woocommerce_package_rates', 'hide_flat_rate_when_free_is_available', 100, 2 );function hide_flat_rate_when_free_is_available( $rates, $package ) { // Debug: write to the WooCommerce log. wc_get_logger()->info( 'Package rates: ' . print_r( array_keys( $rates ), true ), array( 'source' => 'shipping-debug' ) );
$free_shipping_exists = false;
foreach ( $rates as $rate_id => $rate ) { if ( strpos( $rate_id, 'free_shipping' ) === 0 ) { $free_shipping_exists = true; break; } }
if ( $free_shipping_exists ) { foreach ( $rates as $rate_id => $rate ) { if ( strpos( $rate_id, 'flat_rate' ) === 0 ) { unset( $rates[ $rate_id ] ); } } }
return $rates;}The filter runs late with priority 100, after most shipping methods have added their rates. The logger call is useful while troubleshooting and can be removed after confirming the rate IDs on your store.