When you have a number of possible shipping options available but one of them is free, there is no point making your customer choose between them. This code hides any paid options when free shipping is available.
/**
* Hide shipping rates when free shipping is available
*/
add_filter('woocommerce_package_rates', 'cc_hide_shipping_when_free_is_available', 100);
function cc_hide_shipping_when_free_is_available($rates) {
$free = array();
foreach ($rates as $rate_id => $rate) {
if ('free_shipping' === $rate->method_id) {
$free[$rate_id] = $rate;
break;
}
}
return ! empty($free) ? $free : $rates;
}
View Raw
Code ID: 91031