Paul
(@paulherrmann)
Here is my snippet, feel free to modify as you need.
function hide_flat_rate_if_free_shipping_available($rates) {
$free_shipping = false;
$flat_rate = false;
// Check available methods
foreach ($rates as $rate_id => $rate) {
if ('free_shipping' === $rate->method_id) {
$free_shipping = true;
}
if ('flat_rate' === $rate->method_id) {
$flat_rate = $rate_id;
}
}
// If both methods are available, remove flat rate shipping and keep free shipping
if ($free_shipping && $flat_rate) {
unset($rates[$flat_rate]);
}
return $rates;
}
add_filter('woocommerce_package_rates', 'hide_flat_rate_if_free_shipping_available', 100);
Thread Starter
Dnn
(@dnn)
Thank you
But I have already made changes directly to the plugin so that it gives the discount on shipping costs, hiding the most expensive ones. I have been using it with some clients for a few months without any problems.
I can share the modified plugin here if you want.