Force local pickup to be the last choice in your shipping options

If you would like to show your Local pickup shipping method as the very last option in your checkout page shipping methods, then you can use the following code.

function wc_force_local_pickup_last ($rates, $package) {
				$method = array();
				$local_pickup = false;
				$count_position = 0;
				foreach( $rates as $key => $rate ) {
					$method[] = $rate->method_id;
					if ($rate->method_id == "local_pickup") {
						$local_pickup = $key;
					}
					$count_position++;
				}
				if ($local_pickup !== false) {
					$temp = array();
					$temp = $rates[$local_pickup];
					unset($rates[$local_pickup]);
					$rates[$local_pickup] = $temp;
				}

	return $rates;
}
add_filter( 'woocommerce_package_rates' , 'wc_force_local_pickup_last', 10, 2 );

This code can be added following the instructions here:

How to add custom code to your WooCommerce/WordPress site the right way

Have any feedback? Be sure to let me know here: Contact me

Share your thoughts

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