Skip to content

Early-bird lifetime licence: $199 once, for the first 200 buyers only. See the offer

Hide other shipping rates when free shipping is available

When a WooCommerce order qualifies for free shipping, hide the paid shipping rates and keep only free shipping and local pickup.

  • Type PHP
  • Runs Everywhere
PHP
// When free shipping is available, hide paid rates. Local pickup stays available.
add_filter(
	'woocommerce_package_rates',
	function ( $rates ) {
		$free = array();
		$keep = array();

		foreach ( $rates as $rate_id => $rate ) {
			if ( 'free_shipping' === $rate->get_method_id() ) {
				$free[ $rate_id ] = $rate;
			} elseif ( in_array( $rate->get_method_id(), array( 'local_pickup', 'pickup_location' ), true ) ) {
				$keep[ $rate_id ] = $rate;
			}
		}

		return $free ? $free + $keep : $rates;
	},
	100
);

What it does

When a cart qualifies for free shipping, WooCommerce still lists your paid rates next to it. Some customers pick the paid option by mistake.

This snippet hides every other rate whenever a free shipping rate is available. Local pickup stays, so customers can still collect in person. It works with both the block checkout and the classic checkout.

Good to know

  • WooCommerce stores shipping rates in the customer's session. To see the change while testing, update the cart or use a private window.

Move your snippets over this afternoon.

Importing changes nothing until you switch over, and your old shortcodes keep working.