Here’s how you can add a “calendar” field on the WooCommerce checkout page, let people decide the delivery date, and save this value in the order.
It took me ages to implement this for a client (it was much more complex, with available dates, different calendars based on different shipping zones, max weight per day, etc) so I thought of sharing the basic snippet with you! Enjoy ๐
PHP Snippet: Display Order Delivery Date @ WooCommerce Checkout
/**
* @snippet Display Order Delivery Date @ WooCommerce Checkout
* @how-to Get CustomizeWoo.com FREE
* @author Rodolfo Melogli
* @compatible WooCommerce 8
* @community https://businessbloomer.com/club/
*/
// -------------------------------
// 1. Display Checkout Calendar if Shipping Selected
add_action( 'woocommerce_review_order_before_payment', 'bbloomer_echo_acf_date_picker' );
function bbloomer_echo_acf_date_picker( $checkout ) {
echo '<div id="show-if-shipping" style="display:none"><h3>Delivery Date</h3>';
woocommerce_form_field( 'delivery_date', array(
'type' => 'text',
'class' => array( 'form-row-wide' ),
'id' => 'datepicker',
'required' => true,
'label' => 'Select Delivery Date',
'placeholder' => 'Click to open calendar',
));
echo '</div>';
}
add_action( 'woocommerce_after_checkout_form', 'bbloomer_show_hide_calendar' );
function bbloomer_show_hide_calendar( $available_gateways ) {
wc_enqueue_js( "
function show_calendar( val ) {
if ( val.match('^flat_rate') || val.match('^free_shipping') ) {
jQuery('#show-if-shipping').fadeIn();
} else {
jQuery('#show-if-shipping').fadeOut();
}
}
jQuery(document).ajaxComplete(function() {
var val = jQuery('input[name^=\'shipping_method\']:checked').val();
show_calendar( val );
});
" );
}
add_action( 'woocommerce_checkout_process', 'bbloomer_validate_new_checkout_fields' );
function bbloomer_validate_new_checkout_fields() {
if ( isset( $_POST[ 'delivery_date' ] ) && empty( $_POST[ 'delivery_date' ] ) ) wc_add_notice( __( 'Please select the Delivery Date' ), 'error' );
}
// -------------------------------
// 2. Load JQuery Datepicker
add_action( 'woocommerce_after_checkout_form', 'bbloomer_enable_datepicker', 10 );
function bbloomer_enable_datepicker() {
echo '<link rel="stylesheet" href="//code.jquery.com/ui/1.13.0/themes/base/jquery-ui.css">';
echo '<script src="//code.jquery.com/ui/1.13.0/jquery-ui.js"></script>';
}
// -------------------------------
// 3. Load Calendar Dates
add_action( 'woocommerce_after_checkout_form', 'bbloomer_load_calendar_dates', 20 );
function bbloomer_load_calendar_dates( $available_gateways ) {
wc_enqueue_js( "
$('#datepicker').click(function() {
$('#datepicker').datepicker({
dateFormat: 'dd-mm-yy',
maxDate: '+2m',
minDate: 1,
}).datepicker( 'show' );
});
" );
}
// -------------------------------
// 4. Save & show date as order meta
add_action( 'woocommerce_checkout_update_order_meta', 'bbloomer_save_date_weight_order' );
function bbloomer_save_date_weight_order( $order_id ) {
if ( $_POST['delivery_date'] ) update_post_meta( $order_id, '_delivery_date', esc_attr( $_POST['delivery_date'] ) );
}
add_action( 'woocommerce_admin_order_data_after_billing_address', 'bbloomer_delivery_weight_display_admin_order_meta' );
function bbloomer_delivery_weight_display_admin_order_meta( $order ) {
echo '<p><strong>Delivery Date:</strong> ' . get_post_meta( $order->get_id(), '_delivery_date', true ) . '</p>';
}
Is There a Plugin For That?
If you’d love to code but don’t feel 100% confident with PHP, I decided to look for a reliable plugin that achieves the same result.
In this case, I recommend the WooCommerce Delivery Slots plugin. On top of showing a date & time picker on the checkout page, you can also restrict hours and days, charge fees and premium for specific slots and much more.
But in case you hate plugins and wish to code (or wish to try that), then keep reading ๐
I’m using this on Woo 5.9 at the moment with a variety of themes. It doesn’t work immediately but two changes resolve the issue and it works like a dream!
At line 76 change the jQuery version from 1.11.4 to 1.13.0
Insert a line at 75 linking to your preferred jQuery UI stylesheet
Hope you don’t mind my contribution Rodolfo!
Thanks a million Simon, super useful!
Hi, After adding the PHP Snippet: Display Order Delivery Date @ WooCommerce Checkout the color of view cart and checkout buttons in the cart tray at the site header has been changed to grey and I can not change it to any other colors. Please help me with that.
Did you copy the exact snippet? Seems like a CSS / JS / HTML syntax error
Hello,
And thank you for this great solution !!
I just have an error showing in the console of my chrome browser:
Uncaught TypeError: Cannot read property ‘match’ of undefined
at show_calendar ((index):431)
at HTMLDocument. ((index):440)
at HTMLDocument.dispatch (jquery.js?ver=1.12.4-wp:3)
at HTMLDocument.r.handle (jquery.js?ver=1.12.4-wp:3)
at Object.trigger (jquery.js?ver=1.12.4-wp:3)
at x (jquery.js?ver=1.12.4-wp:4)
at XMLHttpRequest.c (jquery.js?ver=1.12.4-wp:4)
Can you tell me how to fix it ??
Because I am new to programming !!
I thank you in advance. ๐
Hi Fouquet, this will require custom troubleshooting. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!
Hello,
How can i add both datetime picker and Local Pickup together with the code?
Thanks
Hi Ammar, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!
Hi Rodolfo,
Thanks for the nice snippet! I only have 2 questions. How can I let customers choose a date at min. 2 days later. Example: I order on Monday so I can choose only a date from Wednesday (so not Tuesday). Second question is how to exclude weekend?
Thanks in advance.
Vasco
Hi Vasco, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!
Hi there,
Firstly a big thank you for your contributions. I have used your code through a plugin called snippets as I dont have a child theme. The datepicker is not loading. However, the validation of required date field is catching on submit.
If I remove the style=”display:none”, then it shows up. However, the date picker doesn’t load. I am using a plugin called Checkout Manager for Woocommerce by Quadlayers. Can that plugin be the cause? Even in that plug-in, the date picker is not loading if I put conditions like min and maxdate.
Can you please help.
Could be anything Durlov. Try disabling all plugins but Woo and switch theme temporarily, and see if it works
Hi, I want to display “Pickup calendar” at shop page. I have a table layout shop page. where i can bulk select the items. Is there any way that i can add the pickup date calendar at that page.
Hi Janjua, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!
Why i cannot select a date from next month or something. Selection is limited to around 10 days . I want to make it flexible. Plz help asap!
It should actually let you select dates for the next 2 months (maxDate)
Hi
Can you tell me how to show allow customer to select delivery date and time at the product detail page. The the above tutorial is best to show at checkout page. I want to show at product detail page
Rahul, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!
Not show delivery date in order view page in backend.
It should. Can you try with a different theme and no other plugin but Woo?
I want it to show up when the items belong to some categories and would be delivired to a designated location.
I hope I could get your helps.
Hi Aaron, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!
Hi Rodolfo,
Does this snippet still work? I just deployed on my staging website and it does not show up.
Best regards,
Ricardo
Yep, it should. Can you try with another theme?
Hi rodolfo,
I need a special help but i don’t know where i can find it… I explain myself. I have buy a plugin WooCommerce Order Delivery OR Pick up Date it’s a cool plugin work great but not support anymore by the maker… This pickup date appear on order and i realy need that the calendar appear in my product page … i’m sure there is a way on the php file to put the calendar to another place but my knowledge are not sufficient to do that.. Maybe you can help me if i show you the files or something like that. Thanks a lot
Hello Melanie, thanks so much for your comment! Yes, this is possible – but unfortunately this is custom work and I cannot provide a complementary solution here via the blog comments. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding! ~R
Hey is it possible to set minimum delivery date so I can offer handmade products? So that it’s different with each product
Hey Matt – thanks so much for your comment! Yes, this is possible – but unfortunately this is custom work and I cannot provide a complementary solution here via the blog comments. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding! ~R
Great snippet! Could it be synched with subscriptions?
Hey Alexandre, thanks so much for your comment! Yes, this is possible – but unfortunately this is custom work and I cannot provide a complementary solution here via the blog comments. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding! ~R
Hello Friend. Thanks for the snippet, it works great!
Q: Is there an option to add the delivery date to your order email?
Hello Aramon, thanks so much for your comment! Yes, this is possible – but unfortunately this is custom work and I cannot provide a complementary solution here via the blog comments. Thanks a lot for your understanding! ~R
Nice one! Does something like this work for digital downloads? For example, someone buying a gift voucher for another person, they enter the recipient’s email on checkout and when they select a date would it delay the email with the voucher attached from being sent until selected date?
Hey Mike, yes that could be done – but you need to make the two systems “talk” with additional PHP ๐
Thanks Rodolfo for your wonderful mega snippet! This would a super time saver for many others. ๐
Excellent ๐
Thanks for your tutorials. Today my PM required me to implement this function for our client’s website.
Much appreciate!
Great ๐