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 Build a Customer Loyalty and Rewards Program for Your WooCommerce Restaurant: Points, Punch Cards, and VIP Tiers to Drive Repeat Orders (Complete Guide)

Why Restaurant Loyalty Programs Matter for Online Ordering A customer places their first order through your restaurant’s website. The food arrives hot, the experience is seamless, and they’re satisfied. But will they come back? Without a deliberate strategy to encourage repeat visits, there’s a strong chance they’ll drift to a competitor or default back to […]
April 7, 2026
Tutorials

How to Secure Your WooCommerce Restaurant Website: Protect Customer Payment Data, Prevent Hacking, and Set Up SSL, Firewalls, and PCI Compliance (Complete Guide)

Why Restaurant Website Security Matters More Than You Think A single data breach can shut down a restaurant faster than a failed health inspection. That’s not hyperbole — when a small restaurant loses customer credit card data, the average cost of remediation, fines, and lost business can reach tens of thousands of dollars. For an […]
April 7, 2026
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