Checkout: give a discount for local pickup

I had to add a discount for local pickup and at first this looked easy. You can set the costs to be a negative amount. But if the subtotal for the order was smaller then the discount, they got the order for free. So I wanted the discount only if the order subtotal was more then twice the discount.

  1. Create two ‘local pickup’ shipping methods.
  2. The costs of one should be 0 or positive the other negative (-20)
  3. Observe them in a real checkout and ‘right click / inspect element’ to see the ID
  4. Use the ID in the script below

Place the script below in your theme’s functions.php or plugin.

add_filter( 'woocommerce_package_rates', 'puddinq_tiered_shipping', 10, 2 );
 
function puddinq_tiered_shipping( $rates, $package ) {
 
    $threshold = 100;
 
    if ( WC()->cart->subtotal < $threshold ) {
        unset( $rates['local_pickup:5'] );
    } else {
        unset( $rates['local_pickup:6'] );
    }
 
    return $rates;
 
}

In point 3 you saw an ID simular to local_pickup:5 this should be the one without the discount.