Woocommerce If Free Shipping Is Available Hide Other Shipping

Just add your theme functions.php and test it.

function hide_other_shipping_when_free_is_available( $rates, $package ) {
$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', 'hide_other_shipping_when_free_is_available', 100, 2 );

Written by Uğur

Leave a Reply

Your email address will not be published. Required fields are marked *