Code To Add Free Shipping Minimum in WooCommerce

This PHP code enables you to set a minimum order purchase limit for free shipping in WooCommerce. Once the minimum order is reached, the free shipping method becomes active and displays on your cart page along with all your other shipping methods..


add_filter('woocommerce_package_rates', 'custom_woocommerce_available_shipping_methods', 100);
function custom_woocommerce_available_shipping_methods($rates) {
    $free_shipping_minimum = 100; // Set your minimum cart total for free shipping here
    $cart_total = WC()->cart->get_subtotal();

    if ($cart_total >= $free_shipping_minimum) {
        foreach ($rates as $rate_id => $rate) {
            if ('free_shipping' === $rate->method_id) {
                $free_shipping_rate = $rates[$rate_id];
                $rates = array($rate_id => $free_shipping_rate);
                break;
            }
        }
    }
    
    return $rates;
}

The code displays all other shipping methods when your cart total is below the minimum amount and only includes the free shipping method once the total reaches your preset limit.

The screenshot above shows shows the free shipping method added to the cart page once the minimum order amount has reached your preset limit.

Remove Shipping Methods

If you want to remove other shipping methods once your cart total reaches the minimum order amount and only display free shipping, you can use a plugin like Free Shipping for WooCommerce.

You can modify and extend the code to do anything you like.

Need More Coding Help?

Book a Consultation

Was This Tutorial Helpful?

Free

$0

Access only to all free tutorials per month.



Monthly

$75

Access to 10 premium tutorials per month.


Tutorial Request


Includes code guarantee and coding support.

Yearly

$500

Access to 15 premium tutorials per month.


Monthly Tutorial Request


Includes code guarantee and priority coding support.