WPSlash Licences

Set Delivery and Pickup Time From Product Processing Time

How to Dynamically Adjust Delivery and Pickup Time in WooCommerce Based on Product Processing Time – code snippet guide from WPSlash
Published
Updated
Reading time
2 minutes
Written by
WPSlash team

This snippet makes the pickup and delivery estimate in FoodMaster (formerly WooFood) follow the longest processing time in the cart. Add it to your child theme’s functions.php file, or to a code snippets plugin.

Set the pickup time from the cart

The snippet reads the process_time_woocommerce custom field of every product in the cart and returns the highest value. A product without that field counts as 0.

Updated for current FoodMaster versions: the code below uses the foodmaster_ names. Older installs that still run WooFood used the woofood_ prefix, so on those change foodmaster_ back to woofood_.

Code
add_filter("foodmaster_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 the snippet works

The function hooks into foodmaster_adjust_pickup_time. It loops over the cart, collects the processing time of each product, and returns the maximum. If the cart is empty, it returns the default time it was given.

Before you start

  • Set a processing time for each menu item in the process_time_woocommerce custom field.
  • To check it worked, add two items with different processing times to the cart and open the checkout. The estimate should match the slower item.
  • Test on a staging site before you use it on the live shop.

FoodMaster (formerly WooFood)

The snippet uses a filter from FoodMaster (formerly WooFood), the restaurant ordering plugin for WooCommerce. You can get FoodMaster here.

FoodMasterRestaurant ordering for WooCommerce: delivery, pickup and dine-in, a POS for counter and phone orders, a kitchen display and automatic ticket printing. Used by 10,000+ restaurants.$499 for one site
All guides

FoodMaster (formerly WooFood)12 min read

Best Store Address Setup for Pickup

Compare single-address, multi-location, and directions-first pickup setups to reduce wrong-door visits and simplify checkout.

The plugins these guides are about

FoodMaster for restaurants, courier vouchers for the Greek market, marketplace sync and store tools, all for WooCommerce.

Browse plugins30-day money-back on every plugin