WPSlash

How to Restrict Delivery to Specific Cities

Saturday February 21, 2026

FoodMaster’s cities restriction mode lets you define which cities or areas are eligible for delivery. But sometimes the built-in settings are not granular enough — you need to add cities dynamically, exclude certain postcodes within an allowed city, or update the list without going into the admin settings. The woofood_cities_restrictions filter gives you full programmatic control.

Understanding the Cities Delivery Type

FoodMaster supports three delivery zone methods: radius (distance in km or miles from your restaurant), postal code (a list of allowed postcodes), and cities (a list of allowed cities or areas). The cities method is ideal for restaurants that deliver across clearly defined neighbourhoods or towns without needing precise distance calculations.

When the cities type is active, FoodMaster compares the customer’s entered city against the allowed list. The woofood_cities_restrictions filter lets you modify that list dynamically in code.

FoodMaster delivery cities restriction settings in WordPress admin

The woofood_cities_restrictions Filter

The filter receives the current array of allowed cities (as configured in the admin settings) and expects you to return a modified array. City names are compared case-insensitively.

add_filter( 'woofood_cities_restrictions', 'my_prefix_delivery_cities' );

function my_prefix_delivery_cities( $cities ) {
    // $cities is an array of allowed city name strings
    // Return a modified array
    return $cities;
}

Practical Use Cases with Code Examples

Example 1 — Whitelist a Fixed Set of Cities in Code

If you prefer to manage your delivery cities entirely in code rather than the admin panel, replace the admin list with a hardcoded array.

add_filter( 'woofood_cities_restrictions', 'my_prefix_fixed_city_list' );

function my_prefix_fixed_city_list( $cities ) {
    return array(
        'London',
        'Hackney',
        'Islington',
        'Shoreditch',
        'Bethnal Green',
        'Spitalfields',
    );
}

Example 2 — Add Cities Dynamically from a Custom Database Table

If your delivery coverage changes frequently, store the city list in a custom database table or a post type and pull it at runtime.

add_filter( 'woofood_cities_restrictions', 'my_prefix_cities_from_db' );

function my_prefix_cities_from_db( $cities ) {
    // Example: cities stored as a serialised option
    $custom_cities = get_option( 'my_restaurant_delivery_cities', array() );

    if ( ! empty( $custom_cities ) && is_array( $custom_cities ) ) {
        // Merge with admin-configured cities rather than replacing
        return array_unique( array_merge( $cities, $custom_cities ) );
    }

    return $cities;
}

Example 3 — Restrict Cities by Day of the Week

Some restaurants deliver to outer areas only on specific days when they have extra capacity.

add_filter( 'woofood_cities_restrictions', 'my_prefix_cities_by_day' );

function my_prefix_cities_by_day( $cities ) {
    $now        = new DateTime( 'now', new DateTimeZone( wp_timezone_string() ) );
    $day_of_week = (int) $now->format( 'N' ); // 1=Monday, 7=Sunday

    // Only deliver to outer areas Thursday–Saturday (4,5,6)
    if ( in_array( $day_of_week, array( 4, 5, 6 ), true ) ) {
        $cities[] = 'Stratford';
        $cities[] = 'Forest Gate';
        $cities[] = 'Walthamstow';
    }

    return $cities;
}

Switching to Cities Mode

To use cities-based delivery, go to FoodMaster → Settings → Delivery → Distance / Zone Type and select Cities. Then add your initial city list in the text area below. The woofood_cities_restrictions filter will modify this list dynamically at runtime.

If you want to control the distance type entirely in code, you can also use the woofood_distance_type_filter filter to switch to cities mode programmatically:

add_filter( 'woofood_distance_type_filter', function( $type ) {
    return 'cities'; // force cities mode: 'radius', 'postal', or 'cities'
} );

Frequently Asked Questions

Is the comparison case-sensitive?

No. FoodMaster performs a case-insensitive comparison, so “London”, “london”, and “LONDON” all match.

Can I use partial matches (e.g., only the first part of a city name)?

The cities filter works with exact matches. For partial matching or postcode-prefix logic, use the postal code delivery type combined with the woofood_check_postal_prefixes filter, which enables prefix-based postal code matching.

What happens if the customer’s city is not on the list?

FoodMaster will display a “delivery not available to your area” message and prevent checkout from proceeding for delivery. Pickup and dine-in options remain unaffected.

Does this work with multistore?

Yes. In a multistore setup, delivery zone settings are managed per store. The filter runs during the active store’s checkout flow, so you can detect the current store and return different city lists accordingly.

Wrapping Up

The woofood_cities_restrictions filter is a clean way to manage delivery coverage without returning to the admin settings every time your delivery zone changes. Whether you want to manage cities from a database, add seasonal areas, or expand on specific days, a small PHP snippet handles it cleanly.

Questions or edge cases? Open a support ticket and the FoodMaster team will help you get the right logic in place.

Leave a Comment

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