How to Set a Custom Cutoff Time for Specific Products
In some cases, you may want to enforce a different cutoff time for certain products. For example, perishable or made-to-order products might require customers to book delivery slots earlier than usual.
WooCommerce Delivery Slots allows you to apply a global cutoff time, but with a small code snippet, you can override this setting for specific products in the cart.
This guide shows you how to set a custom cutoff time (in minutes) for selected product IDs.
Purpose of the snippet
This snippet checks the customer’s cart, and if any of the specified products are present, the plugin will automatically update the cutoff time to the value you define.
This is useful when:
- Certain items need more preparation time.
- You sell mixed products, but only some need an early cutoff.
- You want dynamic cutoff times without modifying global settings manually.
Code snippet
<?php
/**
* Iconic WDS - Modify cutoff time for specific products.
*/
function iconic_modify_cutoff_time_for_specific_products() {
// @todo Replace with your product ids and their respective cutoff times in minutes.
$product_ids = array(
// product id => cutoff time in minutes
120 => '60',
150 => '90',
);
global $iconic_wds;
foreach ( $product_ids as $product_id => $cutoff_time ) {
if ( iconic_is_product_in_cart( $product_id ) ) {
$iconic_wds->settings['timesettings_timesettings_cutoff'] = intval( $cutoff_time );
}
}
}
add_action( 'wp_loaded', 'iconic_modify_cutoff_time_for_specific_products', 11 );
Modify the code snippet where it says @todo. That’s where you have to replace the product ID’s array. The key of the array is the product ID, and the value of the array is the cutoff time in minutes.
WooCommerce Delivery Slots
Let customers choose their preferred WooCommerce delivery date and time right from your WooCommerce checkout page. With WooCommerce Delivery Slots, you can set a flexible delivery schedule to suit you and your customers.
Was this helpful?
Please let us know if this article was useful. It is the best way to ensure our documentation is as helpful as possible.