When a customer qualifies for free shipping, show only the free option instead of making them pick it from a list of paid ones.
add_filter( 'woocommerce_package_rates', function ( array $rates ): array {
$free = array_filter( $rates, fn ( $rate ) => 'free_shipping' === $rate->get_method_id() );
// Keep local pickup available alongside free shipping.
$pickup = array_filter( $rates, fn ( $rate ) => in_array( $rate->get_method_id(), [ 'local_pickup', 'pickup_location' ], true ) );
return $free ? $free + $pickup : $rates;
}, 100 );
Always add PHP to a staging site first, or have FTP or file manager access ready, so you can undo it if something goes wrong.
When an order qualifies for free shipping, WooCommerce still lists your paid rates next to it. Customers can pay for shipping by mistake. This snippet removes the paid options whenever free shipping is available.
WooCommerce calculates the available rates for each shipping package and passes them through woocommerce_package_rates. The snippet looks for rates from the Free shipping method. If there are any, it returns only those, plus local pickup so customers can still collect in person.
It runs at priority 100, after most shipping plugins have added their rates.
$pickup check.Add enough to the cart to qualify for free shipping and open the cart. Only Free shipping (and local pickup, if you offer it) should be listed.