Skip to content

Instantly share code, notes, and snippets.

@wpflames
Created March 22, 2022 11:52
Show Gist options
  • Select an option

  • Save wpflames/8b7b9f9504818a1d836c895c98f7081e to your computer and use it in GitHub Desktop.

Select an option

Save wpflames/8b7b9f9504818a1d836c895c98f7081e to your computer and use it in GitHub Desktop.
Unset All Shipping Methods if Free Shipping is Available
// =========================================================================
// Unset Shipping Methods if Free Shipping is Available
// =========================================================================
function 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;
}
}
add_filter( 'woocommerce_package_rates', 'unset_shipping_when_free_is_available_all_zones', 9999, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment