Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
WooCommerce: enable locale delivery only when minimum amount is reached
* Disable local delivery when a minimum amount is not reached.
* The minimum amount is the free shipping one.
function setMinimumAmountForLocalDelivery($isAvailable) {
// get cart amount :
if (WC()->cart->prices_include_tax) {
$cartAmount = WC()->cart->cart_contents_total + array_sum(WC()->cart->taxes);
} else {
$cartAmount = WC()->cart->cart_contents_total;
// get free shipping amount :
$freeShippingSettings = get_option("woocommerce_free_shipping_settings");
$freeShippingMinimumAmount = $freeShippingSettings["min_amount"];
// disable local delivery when required
if ($cartAmount < $freeShippingMinimumAmount) return false;
return $isAvailable;
add_filter("woocommerce_shipping_local_delivery_is_available", "setMinimumAmountForLocalDelivery", 20);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment