WPSlash

Set a Minimum Order amount per Zip Code

Friday July 10, 2020

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

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