/*
Theme Name: TheAisle Child
Theme URI: http://theaisle.elated-themes.com
Description: A child theme of TheAisle Theme
Author: Elated Themes
Author URI: http://themeforest.net/user/elated-themes
Version: 1.0.0
Text Domain: theaisle
Template: theaisle
*/

function wpspecial_spedizione_gratuita_automatica( $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;
} 

}
add_filter( 'woocommerce_package_rates', 'wpspecial_spedizione_gratuita_automatica', 10, 2 );