Created
May 3, 2016 21:56
-
-
Save partageit/53cf30f4a743fb236bba970d6b62f535 to your computer and use it in GitHub Desktop.
WooCommerce: enable locale delivery only when minimum amount is reached
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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