# Select the Cheapest Shipping Method by Default

> Preselects the lowest-priced shipping option for new carts instead of whichever method happens to be first in the zone.

- Type: PHP
- Runs: Run everywhere
- Category: [WooCommerce](https://wpide.com/library/category/woocommerce/)
- Requires: WooCommerce
- Tags: woocommerce, shipping, checkout
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/woo-default-cheapest-shipping/

## Code

```php
add_filter( 'woocommerce_shipping_chosen_method', function ( $default, $rates, $chosen ) {
    if ( $chosen && isset( $rates[ $chosen ] ) ) {
        return $chosen;
    }

    $cheapest = $default;
    $lowest   = null;

    foreach ( $rates as $id => $rate ) {
        $cost = (float) $rate->get_cost();

        if ( null === $lowest || $cost < $lowest ) {
            $lowest   = $cost;
            $cheapest = $id;
        }
    }

    return $cheapest;
}, 10, 3 );
```

## Notes

Only sets the default; a method the customer picks themselves is kept.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Select the Cheapest Shipping Method by Default" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
