WPSlash

Set a Minimum Order amount per Zip Code

Here is a small snippet on how to set a minimum amount for for delivery per zip code

Just copy and paste the following code snippet your functions.php on your child theme.

add_action( 'woocommerce_checkout_process', 'woofood_custom_hook_minimum_per_zipcode', 9999999 );
 function woofood_custom_hook_minimum_per_zipcode() {
   global $woocommerce;

    $minimum = array();

    //add postal code to array with value the minimum amount without spances//
    $minimum["45565"] = 15;
    $minimum["56654"] = 20;
    $billing_postcode = isset($_POST["billing_postcode"]) ? str_replace(" ", "", $_POST["billing_postcode"]) : "";
    
   

    if ( (isset($_POST["woofood_order_type"]) && ($_POST["woofood_order_type"] == "delivery")  )) {


    if (array_key_exists($billing_postcode, $minimum) &&  ( WC()->cart->subtotal < $minimum[$billing_postcode])  )
    {
          wc_add_notice( 
                sprintf(  __( 'You must have an order with a minimum of %s to place your order, your current order total is %s.', 'woofood-plugin' ) , 
                    wc_price( $minimum[$billing_postcode] ), 
                    wc_price( WC()->cart->subtotal )
                ), 'error' 
            );

    }
    else if(!array_key_exists($billing_postcode, $minimum))
    {
        wc_add_notice( 
                sprintf(  __( 'Sorry, but we are not deliving to postal code %s.', 'woofood-plugin' ) , 
                    $billing_postcode

                ), 'error' 
            );
    }

      

    }
}

Leave a Comment

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

Related Articles

Tutorials

How to Handle Allergen Labeling, Tax Configuration, and GDPR Compliance for Your WooCommerce Restaurant Ordering Website: Legal Requirements Every Online Food Business Must Follow (Complete Guide)

Why Legal Compliance Matters for Online Restaurant Ordering Systems Running a restaurant online isn’t just about beautiful food photography and a smooth checkout flow. The moment you accept orders through a website, you step into a legal landscape that’s significantly more complex than what a brick-and-mortar-only restaurant faces. You’re simultaneously a food service provider, an […]
April 6, 2026
Tutorials

How to Set Up Email Marketing Automation for Your WooCommerce Restaurant: Abandoned Cart Recovery, Post-Order Follow-Ups, and Promotional Campaigns with Mailchimp and AutomateWoo (Complete Guide)

Why Email Marketing Is Essential for WooCommerce Restaurants A customer places an order from your restaurant on a Tuesday night, enjoys the meal, and then… disappears. Not because the food was bad, but because nothing reminded them to come back. This is the reality for most restaurants operating without email marketing automation — and it’s […]
April 6, 2026
Tutorials

How to Speed Up Your WordPress Restaurant Website: Image Optimization, Caching, Database Cleanup, and Core Web Vitals Fixes for Faster Menu Loading and Checkout (Complete Guide)

Why Restaurant Website Speed Matters More Than You Think A hungry customer pulls up your restaurant’s website on their phone during a lunch break. They’ve got maybe 15 minutes to place an order for pickup. Your homepage takes four seconds to load, the menu images trickle in one by one, and the checkout page freezes […]
April 5, 2026