WPSlash

Minimum Order Amount Based on Distance with WooFood

Tuesday January 19, 2021

Copy and paste the following snippet inside your functions.php to be able set a minimum order amount based on Distance on Checkout using WooFood .

add_action("wpslash_distance_check_checkout_completed", "wpslash_hook_add_minimum_order_based_on_distance", 10, 3);


function wpslash_hook_add_minimum_order_based_on_distance($distance_km, $store_address, $customer_full_address)
{
  global $woocommerce;

      $total_amount = $woocommerce->cart->cart_contents_total+$woocommerce->cart->tax_total;

       //key : up to km (distance), value: minimum order amount//
      $minimum_delivery = array();
      $minimum_delivery[2] = 10;
      $minimum_delivery[3] = 15;

      $minimum_amount_required = 0;
      $found = false;
      foreach($minimum_delivery as $up_to_km => $min_amount)
      {

        if($distance_km <= $up_to_km)
        {
          $minimum_amount_required = $min_amount;
          $found = true;
          break;
        }


      }
 
      if($found)
      {
              if ($total_amount <$minimum_amount_required )
    {
          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_amount_required ), 
                    wc_price( $total_amount )
                ), 'error' 
            );

    }


      }
      else
      {

          wc_add_notice( 
                __( 'We are not delivering to your location', 'woofood-plugin' ), 'error' 
            );



      }






}

Leave a Comment

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

Related Articles

Tutorials

How to Secure Your WooCommerce Restaurant Website: WordPress Security Checklist for 2025

Running a restaurant website isn’t like running a blog. When your site goes down at 7 PM on a Friday, you’re not losing pageviews — you’re losing actual dinner orders, frustrated customers, and the trust you spent years building. And unfortunately, restaurant sites running WooCommerce have become a favorite playground for attackers in 2024 and […]
May 17, 2026
Tutorials

How to Set Up SMS and WhatsApp Order Notifications for Your WooCommerce Restaurant (2026)

Why SMS and WhatsApp Notifications Matter for Restaurant Orders A customer places an order on your <a href="https://www.wpslash.com/how-to-set-up-real-time-order-tracking-for-your-woocommerce-restaurant-website-2025-2/" title="How to Set Up Real-Time Order Tracking for Your <a href="https://www.wpslash.com/how-to-set-up-catering-and-large-group-orders-on-your-woocommerce-restaurant-website-2025/" title="How to Set Up Catering and Large Group Orders on Your WooCommerce Restaurant Website (2025)”>WooCommerce Restaurant Website (2025)”>restaurant website at 7:15 PM during the Friday rush. […]
May 3, 2026
Tutorials

How to Set Up Real-Time Order Tracking for Your WooCommerce Restaurant Website (2026)

Why Real-Time Order Tracking Matters for Restaurant Websites Picture this: a hungry customer places an order on your <a href="https://www.wpslash.com/how-to-build-a-customer-loyalty-program-for-your-wordpress-restaurant-website-2025/" title="How to Build a Customer Loyalty Program for Your <a href="https://www.wpslash.com/how-to-connect-your-wordpress-restaurant-website-to-doordash-uber-eats-grubhub-2025/" title="How to Connect Your WordPress <a href="https://www.wpslash.com/how-to-rank-your-restaurant-website-on-google-local-seo-for-wordpress-2025/" title="How to Rank Your Restaurant Website on Google: Local SEO for WordPress (2025)”>Restaurant Website to DoorDash, Uber […]
May 3, 2026