Sort WooCommerce shipping: free delivery, pickup, others
Order available shipping rates without changing prices. Preserve IDs, taxes and other methods, with notes on caching and block-based pickup.
To list free delivery first, local pickup second and other options afterwards, reorder the rates that WooCommerce has already calculated. This snippet neither changes availability or prices nor creates a free shipping method.
Settings or code?
For a single zone, first try ordering methods under WooCommerce → Settings → Shipping → Shipping zones. Code is useful when the same method-based rule should apply across packages and zones. The $methods array contains technical identifiers, free_shipping and local_pickup, rather than translated labels.
If you want to hide paid methods, use the relevant WooCommerce setting; this example retains them. See the free shipping requirements guide.
PHP code
On a staging copy, add a PHP snippet set to run everywhere so it is available during AJAX and Store API recalculations. Alternatively, use a child theme's functions.php. The example omits the opening <?php tag; enable it only once.
add_filter( 'woocommerce_package_rates', function ( $rates ) {
if ( ! is_array( $rates ) ) { return $rates; }
$ordered = array();
$methods = array( 'free_shipping', 'local_pickup' );
foreach ( $methods as $method ) {
foreach ( $rates as $key => $rate ) {
if ( $rate instanceof WC_Shipping_Rate && $method === $rate->get_method_id() ) {
$ordered[$key] = $rate;
unset( $rates[$key] );
}
}
}
return $ordered + $rates;
}, 99 );
What the code preserves
It moves the original rate objects while preserving keys, labels, costs and taxes. Rates sharing a method type retain their relative order. Other rates follow without further changes. An empty list stays empty, and each shipping package is handled separately.
Checks and limitations
Test a cart below and above the free shipping threshold, a coupon and an address in another zone. Compare totals and the selected option: the code does not explicitly choose a rate, but ordering may affect the initial choice in a new session. Trigger a fresh calculation after enabling it because WooCommerce can cache rates in the customer session.
woocommerce_package_rates runs during server-side shipping calculation. Extensions may change how results appear in classic or block checkout. Checkout Blocks' newer pickup-location selector is not the same as the zone-based local_pickup method; this example does not reorder that separate location selector. A later filter can change the order again.
Server behaviour was checked with WordPress 7.1.5, WooCommerce 11.3.1 and PHP 8.4.23. Inspect your checkout visually too. To remove the change, disable the snippet and refresh shipping calculations. WooCommerce filter source