Hide local shipping if cart contents are zero in WooCommerce

Hide local shipping if cart contents are zero in WooCommerce on child sites.

Snippet Type

Execute on Child Sites

Snippet

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;
}

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.