Snippet to automatically select Free shipping when possible in WooCommerce

Ever wondered why your customers still have the option to pay for shipping, even when free shipping is available?

There are, of course, cases where you have multiple carriers and you want the customer to select a carrier. But most of the time free shipping is available because the cart price is higher than a defined amount.

To automatically select free shipping when it is available, the only thing you have to do is include the following PHP snippet at the end of your functions.php:

 * Downloaded from
add_filter('woocommerce_package_rates', function ($rates) {
    $free = [];

    foreach ($rates as $rate_id => $rate) {
        if ('free_shipping' === $rate->method_id) {
            $free[$rate_id] = $rate;

    return ! empty($free) ? $free : $rates;
}, 100);

Interested in a webshop or in custom software that works with WooCommerce or connects with WooCommerce? Please get in touch via the form below.

Share this article:

Get in touch

Send a message

Contact information

CoC number:60528125