3

I would like to hide the "Local Pickup" option in WooCommerce shipping options if the order total is zero.

These are what my current options look like:

enter image description here

Have found a pro plugin, but it goes over and beyond what I need. I would prefer a simple code snippet rather than a plugin.

LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399

1 Answers1

2

Based on this related answer, you can use the following, to hide "local pickup" shipping option, if cart contents total is zero:

add_filter( 'woocommerce_package_rates', 'hide_local_pickup_for_free_orders', 10, 2 );
function hide_local_pickup_for_free_orders( $rates, $package ) {
    // If cart subtotal is equal to zero
    if( $package['contents_cost'] == 0 ) {
        foreach( $rates as $rate_key => $rate ) {
            // Hide Local Pickup shipping method(s)
            if ( $rate->method_id === 'local_pickup' ) {
                unset($rates[$rate_key]);
            }
        }
    }
    return $rates;
}

Code goes in functions.php file of your child theme (or in a plugin). Tested and works.

Important note: To refresh shipping method caches, empty your cart.

LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399