Quantcast
Channel: Webkul Blog
Viewing all articles
Browse latest Browse all 5489

Hide other shipping methods if free shipping is available woocommerce

$
0
0

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


Viewing all articles
Browse latest Browse all 5489

Trending Articles