WooCommerce: Hide Other shipping methods if free shipping is available
In case you need to hide other shipping methods if you offer free shipping through the default WooCommerce functionality you may need to hide the rest shipping methods if the order is eligible for free shipping.
Just add the code below to a site-specific plugin or to the functions.php
file of your theme.
// hide other shipping methods if free shipping available
function ik_hide_free_shipping( $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;
}
add_filter( 'woocommerce_package_rates', 'ik_hide_free_shipping', 100 );