B-219 Sec-55 Noida, India
+918010221733

Select Cheapest Shipping Method in WooCommerce

Woocommerce have many shipping methods. If you want to select the cheapest shipping method for your customer then add the below given code in your functions.php


add_filter( 'woocommerce_package_rates' , 'cheapest_woocommerce_shipping_method', 10, 2 );
function cheapest_woocommerce_shipping_method( $rates, $package ) {
	if ( ! $rates ) {
		return;
	}

	$prices = array();
	foreach( $rates as $rate ) {
		$prices[] = $rate->cost;
	}
	
	array_multisort( $prices, $rates );
	
	return $rates;
}
(Visited 319 times, 1 visits today)

Leave a reply