Hide other shipping when shipping is free
When an order qualifies for free shipping, the customer sees only free shipping (and local pickup, if you offer it) instead of paid options too.
<?php
add_filter(
'woocommerce_package_rates',
static function ( $rates ) {
$free = array_filter( $rates, static fn( $rate ) => 'free_shipping' === $rate->get_method_id() );
if ( ! $free ) {
return $rates;
}
$pickup = array_filter( $rates, static fn( $rate ) => in_array( $rate->get_method_id(), array( 'local_pickup', 'pickup_location' ), true ) );
return $free + $pickup;
},
100
);
In these packs
- WooCommerce essentials: The small WooCommerce changes shop owners ask for most.