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!