If you’re running a WooCommerce-powered restaurant ordering system, you may want to set different minimum order amounts for delivery based on the customer’s city. This ensures that delivery remains cost-effective for your business, especially when serving multiple locations.
In this guide, we’ll show you how to use a custom PHP snippet to dynamically adjust the minimum delivery amount per city when using WooFood – the WooCommerce food delivery plugin.
Why Set a Minimum Order Amount Based on City?
✔ Ensures profitability – Prevents small orders from being delivered to far locations.
✔ Customizes delivery pricing – Allows businesses to charge differently per area.
✔ Improves efficiency – Encourages larger orders for deliveries in distant locations.
✔ Seamless WooCommerce integration – Works perfectly with the WooFood Plugin.
By implementing this WooCommerce customization, your customers will only be able to place an order if their total meets the minimum required for their selected city.
How to Set a Minimum Delivery Amount Per City in WooFood
To apply different minimum order amounts per city, insert the following PHP snippet into your child theme’s functions.php
file:
add_filter("woofood_minimum_amount_delivery_filter", "wpslash_minimum_delivery_hook_on_message_per_city", 10, 1);
function wpslash_minimum_delivery_hook_on_message_per_city($min_amount) {
global $woocommerce;
$minimum = array(
"Niefern" => 8,
"Niefern-Öschelbronn" => 8,
"Pinache" => 8,
"Wiernsheim" => 12,
"Neubärental" => 12,
"Großglattbach" => 12,
"PF-Eutingen" => 13,
"Enzberg" => 13,
"Lormersheim" => 13,
"Mönsheim" => 15,
"Wimsheim" => 15,
"PF-Mäurach" => 15,
"PF-Hagenschieß" => 15,
"Kieselbronn" => 15,
"Dürrmenz" => 15,
"Serres" => 15,
"Mühlacker" => 17,
"Mühlacker Mühlhausen" => 17,
"Sengach" => 18,
"Iptingen" => 18,
"PF-Oststadt" => 22,
"Weissach" => 22,
"Friolzheim" => 22,
"PF-Innenstadt" => 25,
"PF-Südstadt" => 25,
"Buckenberg" => 25,
"Haidach" => 25,
"Nußdorf" => 25,
"Lienzingen" => 25,
"Ötisheim" => 25,
"Corres" => 25,
"Öt-Erlenbach" => 25,
"Tiefenbronn" => 25,
"PF-Nordstadt" => 30,
"Bauschlott" => 30,
"Göbrichen" => 30,
"Ölbronn-Dürrn" => 30,
"Eberdingen" => 30,
"Pf-Brötzingen" => 35,
"Pforzheim" => 35,
"Weststadt" => 35,
"Maihälden" => 35,
"Neulingen" => 35
);
$city = str_replace(" ", "", $woocommerce->customer->get_billing_city());
if (array_key_exists($city, $minimum)) {
return $minimum[$city];
}
return $min_amount;
}
How This Code Works
✅ Filters the minimum order amount for WooFood deliveries based on the selected city.
✅ Uses the customer’s billing city to determine the correct minimum amount.
✅ Ensures that customers cannot place orders unless their total meets the city’s requirement.
✅ Works seamlessly with the WooCommerce checkout process.
How to Add a City Selection Dropdown in WooCommerce Checkout
By default, WooCommerce allows customers to enter their city manually. To ensure accuracy, you can replace this field with a predefined list of cities.
Add the following code snippet to your functions.php file to replace the default city field with a dropdown selection:
add_filter('woocommerce_checkout_fields', function($fields) {
$minimum = array(
"Niefern" => 8,
"Niefern-Öschelbronn" => 8,
"Pinache" => 8,
"Wiernsheim" => 12,
"Neubärental" => 12,
"Großglattbach" => 12,
"PF-Eutingen" => 13,
"Enzberg" => 13,
"Lormersheim" => 13,
"Mönsheim" => 15,
"Wimsheim" => 15,
"PF-Mäurach" => 15,
"PF-Hagenschieß" => 15,
"Kieselbronn" => 15,
"Dürrmenz" => 15,
"Serres" => 15,
"Mühlacker" => 17,
"Mühlacker Mühlhausen" => 17,
"Sengach" => 18,
"Iptingen" => 18,
"PF-Oststadt" => 22,
"Weissach" => 22,
"Friolzheim" => 22,
"PF-Innenstadt" => 25,
"PF-Südstadt" => 25,
"Buckenberg" => 25,
"Haidach" => 25,
"Nußdorf" => 25,
"Lienzingen" => 25,
"Ötisheim" => 25,
"Corres" => 25,
"Öt-Erlenbach" => 25,
"Tiefenbronn" => 25,
"PF-Nordstadt" => 30,
"Bauschlott" => 30,
"Göbrichen" => 30,
"Ölbronn-Dürrn" => 30,
"Eberdingen" => 30,
"Pf-Brötzingen" => 35,
"Pforzheim" => 35,
"Weststadt" => 35,
"Maihälden" => 35,
"Neulingen" => 35
);
$fields['billing']['billing_city']['type'] = 'select';
$fields['billing']['billing_city']['options'] = array_merge(array('' => 'Select your city'), $minimum);
return $fields;
});
Looking for a Complete WooCommerce Food Delivery Solution?
If you’re running a food delivery business using WooCommerce, you need a powerful and flexible system to manage orders efficiently.
WooFood – WooCommerce Food Delivery Plugin is the best solution for restaurants that need:
✅ Custom delivery settings – Set minimum order amounts, delivery zones, and fees.
✅ Real-time order processing – Automatically print and manage orders.
✅ Pickup & delivery options – Allow customers to choose their preferred method.
✅ Seamless WooCommerce integration – Works with any WordPress website.
🚀 Upgrade Your WooCommerce Food Ordering System Today!
👉 Get WooFood here to take your restaurant website to the next level!