As a WooCommerce store owner, one of the trickiest parts of running your business is to show the right delivery times to customers. Delivery dates and amount of time might differ for each product based on various factors. On top of that, weekends and holidays can mess with your delivery schedule, making it harder to give your customers the right information.
To address these challenges, plugins such as Product Delivery Date for WooCommerce
can help you to set a unique delivery schedule for different WooCommerce products. The plugin comes with handy features that will let you charge extra for deliveries during peak hours, block out a few days/time-slots, add extra delivery charges for certain products, particular shipping methods, location, delivery on holidays, and peak-hour time slots, etc.
In this post, we’ll show you how to set up custom delivery dates for each product that will exclude weekends and holidays, so your customers always know when to expect their orders, no matter what they’re buying.
Solution: Set Custom Delivery Dates for Each WooCommerce Products (Including Holidays & Weekends)
This code adds a custom field to the WooCommerce product settings page where you can define the “Delivery Lead Time” for each product.
Note: If the “Delivery Lead Time” field is left blank, the default value of 1 day, as specified in the code, will be used.
// Add a custom field for delivery lead time in product settings add_action('woocommerce_product_options_general_product_data', 'ts_add_delivery_lead_time_field'); function ts_add_delivery_lead_time_field() { woocommerce_wp_text_input(array( 'id' => 'delivery_lead_time', 'label' => __('Delivery Lead Time (in days)', 'woocommerce'), 'description' => __('Enter the number of days required for delivery for this product.', 'woocommerce'), 'desc_tip' => true, 'type' => 'number', 'custom_attributes' => array( 'min' => '0', // Minimum delivery time ), )); } // Save the custom field value add_action('woocommerce_process_product_meta', 'ts_save_delivery_lead_time_field'); function ts_save_delivery_lead_time_field($post_id) { $delivery_lead_time = isset($_POST['delivery_lead_time']) ? sanitize_text_field($_POST['delivery_lead_time']) : ''; update_post_meta($post_id, 'delivery_lead_time', $delivery_lead_time); } // Display the estimated delivery date on the product page add_action('woocommerce_after_add_to_cart_form', 'ts_show_estimated_delivery_date'); function ts_show_estimated_delivery_date() { global $product; // Get the delivery lead time for the current product $lead_time = get_post_meta($product->get_id(), 'delivery_lead_time', true); // Fallback to a default lead time if none is set $lead_time = $lead_time ? intval($lead_time) : 1; // Define public holidays $public_holidays = array( '2025-01-20', // Monday (Martin Luther King Jr. Day) '2025-01-22', // Wednesday (Custom Example Holiday) ); // Calculate the initial delivery date $delivery_date = new DateTime(current_time('mysql')); $delivery_date->modify("+{$lead_time} days"); // Adjust for public holidays and weekends while (in_array($delivery_date->format('Y-m-d'), $public_holidays) || in_array($delivery_date->format('N'), array(6, 7))) { $delivery_date->modify('+1 day'); } // Format the delivery date $formatted_date = $delivery_date->format('l, jS F'); // Display the message echo "<div class='woocommerce-message' style='clear:both'>Estimated delivery date: <strong>{$formatted_date}</strong></div>"; }
Firstly, let’s see the settings defined for the delivery lead time field of a particular product. I have set the delivery lead time of 1 day for a specific product.
Let’s test the output with different delivery lead times so that we can check whether the delivery dates are set as per the defined time.
Scenario 1: Lead Time = 1 Day (No weekends or holidays)
- Today’s Date: January 18, 2025 (Saturday)
- Lead Time: 1 Day
- Expected Calculation:January 18 is a Saturday (weekend), so skip to Monday, January 20. January 20 is a public holiday, so skip to Tuesday, January 21.
- Estimated Delivery Date: Tuesday, January 21, 2025
Scenario 2: Lead Time = 2 Days
- Starting Date: January 18, 2025 (Saturday)
- Lead Time: 2 Days
- Expected Calculation:
- January 18 is a Saturday (weekend), so skip to Monday, January 20.
- January 20 is a public holiday, so skip to Tuesday, January 21.
- January 21 is a regular working day, so the 1st day is January 21.
- The 2nd day falls on January 22 (next working day).
- Estimated Delivery Date: Wednesday, January 22, 2025
This configuration skips weekends and public holidays while accurately calculating delivery dates. You can modify the lead time to verify these results further.
You can check the output the different test scenarios in the output video below.
If you want to take things further and let customers select their preferred delivery date from the checkout page, consider using the Order Delivery Date Pro For WooCommerce plugin helping you to create custom delivery schedules tailored to your unique needs. Whether you need to adjust delivery dates by product, product category, shipping method, or even user role, this plugin has got you covered.
In this post, we have covered different customizations that involve setting up delivery dates and timeframes that fit for unique business scenarios. You can implement such customizations easily using code snippets. However, aplugin like Product Delivery Date for WooCommerce can help integrate these features effortlessly, including setting delivery dates, time slots, preparation times, order limits, adding extra fees and many more.