Hide other shipping options in WooCommerce if free shipping is available

It does not look very ideal to show paid shipping options when free shipping is available, unless they are for express delivery. There is no way to set this up directly from WooCommerce. But we can do this easily by modifying available shipping options/rates using woocommerce_package_rates filter.

Following code block checks if free shipping is available. If it finds free shipping, it disables other shipping methods.

function careless_hide_shipping_when_free_is_available( $rates ) {
    $rates_arr = array();
    foreach ( $rates as $rate_id => $rate ) {
        if ( 'free_shipping' === $rate->method_id ) {
            $rates_arr[ $rate_id ] = $rate;

    if ( !empty( $rates_arr ) ) {
        return $rates_arr;

    return $rates;
add_filter( 'woocommerce_package_rates', 'careless_hide_shipping_when_free_is_available', 100 );

Code goes in the functions.php file of your active theme.