Change the minimum delivery date dynamically


Your store normally delivers on the same day (i.e. your minimum delivery date is set to "0"). However, you have one product which requires 4 days to prepare. As such, you want to ensure that the minimum selectable date is set to "4" if a customer has that product in their cart.


You can use the iconic_wds_min_delivery_date filter to modify the minimum selectable date based on items in the cart (or anything else you like).

 * Change minimum delivery date.
 * If a certain product is in the cart (ID 100), add
 * 4 days to the minimum selectable delivery date.
 * @param array $min
 * @return array
function iconic_change_min_delivery_date( $min ) {
	// The product ID to check for in the cart.
	$product_id = 70;

	// If the product is not in the cart, return the original data.
	if ( ! iconic_is_product_in_cart( $product_id ) ) {
		return $min;

	// Add 4 days.
	$days_to_add = 4;

	// This filter returns an array containing the days to add and a timestamp.
	return array(
		'days_to_add' => $days_to_add,
		'timestamp'   => strtotime( "+" . $days_to_add . " day", current_time( 'timestamp' ) ),

add_filter( 'iconic_wds_min_delivery_date', 'iconic_change_min_delivery_date' );

 * Is product in cart?
 * @param $product_id
 * @return bool
function iconic_is_product_in_cart( $product_id ) {
	$product_cart_id = WC()->cart->generate_cart_id( $product_id );
	$in_cart = WC()->cart->find_product_in_cart( $product_cart_id );

	return ! empty( $in_cart );

Drop this code into your child theme's fucntions.php file.

There are 2 functions in play here. The first is iconic_change_min_delivery_date

This is the function that modifies the minimum selectable date, and is called using add_filter below the function itself.

Within this function we assign a product ID of 70 to the $product_id variable. 

This ID is then run through the other function, iconic_is_product_in_cart. This will return true or false, depending on whether that product is in the cart. 

Note: It'll need some modifications to work for variations.

Rather than hardcoding this number, you could loop through cart items and check whether they have a specific custom meta, or belong to a specific category, etc. This is just a simplified example.

If it isn't in the cart, we return $min which is the original data for the filter.

Otherwise, we set the days to add to 4 and build out the array of data that the filter requires.

Now if that product is in the cart, 4 days are added to the minimum selectable date.


It's worth noting that you can do exactly the same for the maximum selectable date using the iconic_wds_max_delivery_date filter.

Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.