WPSlash

How to Set Different Minimum Delivery Amounts Per City in WooCommerce

Saturday July 3, 2021

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!

Leave a Comment

Your email address will not be published. Required fields are marked *

Related Articles

WooFood

How to Disable Coupons for Delivery Orders in WooCommerce

If you’re running a WooCommerce-powered restaurant or food delivery service, you might want to restrict certain coupon codes for delivery orders while keeping them valid for pickup orders. This ensures better control over discounts, prevents misuse, and improves your store’s pricing strategy. Why Restrict Coupons for Delivery Orders? Offering coupons is a great way to attract customers, but in food […]
June 20, 2023
WooFood

How to Automatically Re-Enable Disabled Products in WooFood Once a Day

If you’re running a WooCommerce-powered restaurant ordering system using WooFood, you might have products that automatically get disabled due to stock limits or availability settings. To ensure a smooth customer experience, you can automate the re-enabling process using a scheduled WordPress cron job. This method allows you to reset all product availability once a day, ensuring your menu stays active without manual intervention. Why […]
March 8, 2023
WooFood

How to Add Live Product Search to WooFood in WooCommerce

Enhancing the user experience of your WooCommerce-powered restaurant ordering system is crucial, and adding a live product search feature can significantly improve navigation. This feature allows customers to quickly find food items in your WooFood-powered menu without manually browsing through categories. In this article, we’ll show you how to integrate a live product search above the accordion menu in WooFood using a simple jQuery script and PHP snippet. […]
December 29, 2022