This article will demonstrate that how you can disable other available shipping methods if free shipping is available by using the filters in woocommerce
below is the useful code snippet :-
add_filter( 'woocommerce_package_rates', 'hide_available_shipping_method', 100 );
function hide_available_shipping_method( $rates ) {
$free = array();
foreach ( $rates as $rate_id => $rate ) {
if ( 'free_shipping' === $rate->method_id ) {
$free[ $rate_id ] = $rate;
break;
}
}
// this will return only free shipping method
return ! empty( $free ) ? $free : $rates;
}
If there is something that is not understandable by this blog then do comment below. We will surely assist on that. cheers

Be the first to comment.