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.
![](https://wpsites.net/wp-content/uploads/2024/07/all-shipping-methods-600x236.png)
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?
Was This Tutorial Helpful?