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

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