Skip to content

Instantly share code, notes, and snippets.

@MarceloGlez
Created February 13, 2021 00:58
Show Gist options
  • Save MarceloGlez/429b605309587c3a48fa6e1491439b7d to your computer and use it in GitHub Desktop.
Save MarceloGlez/429b605309587c3a48fa6e1491439b7d to your computer and use it in GitHub Desktop.
Ocultar otros métodos de envío cuando hay envío gratis en Woocommerce
/*Ocultar otros metodos de envio cuando hay envio gratis*/
add_filter( 'woocommerce_package_rates', 'bbloomer_unset_shipping_when_free_is_available_all_zones', 10, 2 );
function bbloomer_unset_shipping_when_free_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;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment