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

Restaurants Tutorials

The Cheapest Food Delivery App for Restaurants Isn’t an App at All — It’s WooFood

When restaurant owners start looking for the cheapest food delivery app, they quickly discover a frustrating truth: most “cheap” delivery platforms aren’t cheap at all. They either take commissions, charge high monthly fees, lock you into their payment processors, or limit how much control you have over your own customer base. But what if the […]
December 1, 2025
Restaurants WooFood

Why “Free” GloriaFood Might Not Be The Best Long-Term Bet For Your Restaurant

When you’re building an online ordering system for your restaurant, it’s tempting to go for a “free” solution. That’s exactly what GloriaFood offers: a ready-to-go, easy-to-install WordPress plugin for online ordering, delivery, and reservations with no setup fees or commissions But “free” doesn’t always mean “best,” especially when you’re serious about owning your brand, your […]
December 1, 2025
Tutorials WooCommerce

How to Choose the Best Food Ordering System for Your Restaurant (And Why WooFood is the Ultimate Solution)

If you’re running a restaurant, café, or fast-food business in today’s digital age, offering online food ordering is no longer optional — it’s essential. Customers expect the convenience of browsing your menu, customizing their orders, and checking out seamlessly from their phone or computer. But with so many plugins and systems available, how do you choose the right […]
April 21, 2025