Webkul
Services
Technologies Bagisto QloApps
iOS Android SAP BigCommerce Wix
Trusted by
Samsung Intel Toyota Walmart Disney Nokia Nestlé Decathlon
See all customers
Back to Top
DEV

Hide other shipping methods if free shipping is available woocommerce

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

. . .

Leave a Comment

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


Be the first to comment.

Back to Top

Message Sent!

If you have more details or questions, you can reply to the received confirmation email.

Back to Home