WPSlash

How to Dynamically Adjust Delivery and Pickup Time in WooCommerce Based on Product Processing Time

Monday February 1, 2021

For restaurants and food delivery services, estimating accurate pickup and delivery times is essential for customer satisfaction. Some menu items take longer to prepare than others, and having a fixed time for all orders can lead to inaccurate delivery expectations.

With WooCommerce and WooFood, you can dynamically calculate the total preparation time based on the longest processing time in the cart. This ensures customers receive a realistic estimated time at checkout.


Why Adjust Delivery & Pickup Time Dynamically?

✔ Provides more accurate order preparation estimates
✔ Prevents customer frustration caused by incorrect delivery times
✔ Improves kitchen efficiency by aligning prep time with order complexity
✔ Works seamlessly with WooFood’s automated order management

By implementing this custom WooCommerce function, the delivery or pickup time dynamically adjusts based on the highest processing time among the ordered items.


How to Set Dynamic Delivery and Pickup Time in WooFood

To calculate pickup and delivery estimates dynamically, insert the following PHP snippet into your theme’s functions.php file:

add_filter("woofood_adjust_pickup_time", "change_dynamically_pickup_time", 10, 1);
function change_dynamically_pickup_time($default)
{
	global $woocommerce;
	if(WC()->cart)
	{
		$woofood_delivery_time = 0;
	 $all_product_times = array();
     $total_time_to_delivery = 0;
      foreach(  WC()->cart->get_cart() as $cart_item  ):

      ## Using WC_Order_Item methods ##

      // Item ID is directly accessible from the $item_key in the foreach loop or
        $item_id = $cart_item['data']->get_id();
	
      $item_name = $cart_item['data']->get_name(); // Name of the product
      $item_type = $cart_item['data']->get_type(); // Type of the order item ("line_item")

      ## Access Order Items data properties (in an array of values) ##
      $item_data = $cart_item['data']->get_data();

      $product_name = $item_data['name'];
			
      $product_id = $item_data['id'];

 
  		$all_product_times[] =  intval(get_post_meta($product_id, 'process_time_woocommerce',  true));

     	 endforeach;

    
                    $woofood_delivery_time = max($all_product_times) + intval($woofood_delivery_time) ;

   
 

    return  $woofood_delivery_time;

  

	}
	else{
		return $default;
	}




  
}

How This Code Works

✅ Iterates through all items in the WooCommerce cart.
✅ Retrieves the processing time for each product.
✅ Determines the maximum processing time among all items.
✅ Adjusts the pickup or delivery time dynamically based on the longest item in the cart.
✅ Works seamlessly with WooFood’s checkout process, ensuring realistic time estimates for customers.


Best Practices for Implementing Dynamic Delivery Time Calculation

🔹 Assign processing times to all menu items under the custom field process_time_woocommerce.
🔹 Test the function to ensure correct pickup and delivery estimates.
🔹 Modify the logic if you want an average preparation time instead of the longest.
🔹 Pair with WooFood’s automatic order management for a smoother workflow.


Take Your WooCommerce Restaurant Ordering to the Next Level with WooFood

Managing delivery and pickup times effectively is essential for streamlined restaurant operations. Instead of using fixed delivery estimates, optimize your WooCommerce food ordering system with WooFood – a powerful plugin for online restaurant orders.

Why Choose WooFood?

✅ Dynamic delivery & pickup times – Custom calculations based on food prep time.
✅ Seamless WooCommerce integration – Works perfectly with any WordPress restaurant website.
✅ Flexible ordering system – Supports takeaway, dine-in, and delivery.
✅ Real-time order tracking – Keep customers informed with accurate time estimates.
✅ Automatic order printing – Send orders directly to the kitchen for faster preparation.

🚀 Upgrade Your WooCommerce Food Delivery System Today!

👉 Explore WooFood – The Best WooCommerce Restaurant Plugin and offer a better ordering experience!

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