WPSlash Licences

Change the Minimum Delivery Amount by Postal Code in FoodMaster

How to Change the Minimum Delivery Amount in the WooCommerce Mini Cart Based on Postal Code – code snippet guide from WPSlash
Published
Updated
Reading time
1 minutes
Written by
WPSlash team

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_.

Code
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_filter filter.
  • 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.

FoodMasterRestaurant ordering for WooCommerce: delivery, pickup and dine-in, a POS for counter and phone orders, a kitchen display and automatic ticket printing. Used by 10,000+ restaurants.$499 for one site
All guides

FoodMaster (formerly WooFood)12 min read

Best Store Address Setup for Pickup

Compare single-address, multi-location, and directions-first pickup setups to reduce wrong-door visits and simplify checkout.

The plugins these guides are about

FoodMaster for restaurants, courier vouchers for the Greek market, marketplace sync and store tools, all for WooCommerce.

Browse plugins30-day money-back on every plugin