Hide all Other Shipping Methods When Free Shipping is Available in WooCommerce?

WooCommerce has multiple shipping settings to establish based on your online store’s needs. It is possible to hide other shipping options when free shipping is available on WooCommerce you need some extra coding.

Hide Other Shipping Methods When Free Shipping is Available

To hide other shipping options when free shipping is available you need to add the following lines of code in your theme's functions.php file.

add_filter( 'woocommerce_package_rates', 'magik_hide_shipping_when_free_shipping_is_available_all_zones', 10, 2 );
  
function magik_hide_shipping_when_free_shipping_is_available_all_zones( $rates, $package ) 
{
     
    $all_free_rates = array();
     
        foreach ( $rates as $rate_id => $rate ) 
        {
          if ( 'free_shipping' === $rate->method_id ) 
          {
            $all_free_rates[ $rate_id ] = $rate;
            break;
          }
        }
     
        if ( empty( $all_free_rates ))
       {
         return $rates;
       } 
        else
      {
        return $all_free_rates;
       } 
}

If you face any problems or need our professional services, please email us at [email protected].

Join our Newsletter

Never miss the latest offers, voucher codes and useful articles delivered weekly in your inbox.