This snippet sets a different minimum delivery amount for each postcode in FoodMaster (formerly WooFood). Add it to your child theme’s functions.php file, or to a code snippets plugin.
Set a minimum amount for each postcode
The snippet holds a list of postcodes and the minimum amount for each one. In the example, 4950 is set to 20 and the other postcodes to 40. Change those values to match your own delivery costs.
Updated for current FoodMaster versions: the code below uses the foodmaster_ names. Older installs that still run WooFood used the woofood_ prefix, so on those change foodmaster_ back to woofood_.
add_filter("foodmaster_minimum_amount_delivery_filter", "wpslash_minimum_delivery_hook_on_message", 10, 1);
function wpslash_minimum_delivery_hook_on_message($min_amount)
{
global $woocommerce;
$minimum = array();
$minimum["4950"] = 20;
$minimum["6153"] = 40;
$minimum["4952"] = 40;
$minimum["4938"] = 40;
$minimum["4944"] = 40;
$minimum["4955"] = 40;
$minimum["4954"] = 40;
$minimum["6144"] = 40;
$minimum["4956"] = 40;
$postalcode = str_replace(" ", "", $woocommerce->customer->get_billing_postcode());
if(array_key_exists($postalcode, $minimum))
{
return $minimum[$postalcode];
}
else{
return $min_amount;
}
}How the snippet works
- It hooks into the
foodmaster_minimum_amount_delivery_filterfilter. - It reads the customer’s billing postcode and removes any spaces.
- If the postcode is in the list, it returns that amount. If not, it returns the amount it was given.
To check it worked, add a product to the cart with a billing postcode from the list and look at the minimum delivery message in the mini cart. A postcode that is not in the list keeps the default amount.
FoodMaster (formerly WooFood)
The snippet uses a filter from FoodMaster (formerly WooFood), the restaurant ordering plugin for WooCommerce. You can get FoodMaster here.
