Skip to content

Instantly share code, notes, and snippets.

@partageit
Created May 3, 2016 21:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save partageit/53cf30f4a743fb236bba970d6b62f535 to your computer and use it in GitHub Desktop.
Save partageit/53cf30f4a743fb236bba970d6b62f535 to your computer and use it in GitHub Desktop.
WooCommerce: enable locale delivery only when minimum amount is reached
<?php
/**
* 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