WooCommerce: Display Order Delivery Date @ Checkout

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 ๐Ÿ™‚

WooCommerce: display a delivery calendar @ checkout

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    Woo 3.7
 * @donate $9     https://businessbloomer.com/bloomer-armada/
 */
 
// -------------------------------
// 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 ) {
    
?>
 
<script type="text/javascript">
    
   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 );
   });
    
</script>
 
<?php
    
}
 
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() {
    
  ?>
 
   <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
 
  <?php    
    
}
 
// -------------------------------
// 3. Load Calendar Dates
 
add_action( 'woocommerce_after_checkout_form', 'bbloomer_load_calendar_dates', 20 );
  
function bbloomer_load_calendar_dates( $available_gateways ) {
 
   ?>
 
   <script type="text/javascript">
 
      jQuery(document).ready(function($) {
             
         $('#datepicker').click(function() {
 
            $('#datepicker').datepicker({ 
               dateFormat: 'dd-mm-yy',
               maxDate: "+2m",
               minDate: 1, 
            }).datepicker( "show" );
             
         });
 
      });
 
   </script>
 
   <?php
  
}
 
// -------------------------------
// 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 ) {
    
    global $woocommerce;
    
    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 ๐Ÿ™‚

Where to add this snippet?

You can place PHP snippets at the bottom of your child theme functions.php file (before "?>" if you have it). CSS, on the other hand, goes in your child theme style.css file. Make sure you know what you are doing when editing such files - if you need more guidance, please take a look at my free video tutorial "Where to Place WooCommerce Customization?"

Does this snippet (still) work?

Please let me know in the comments if everything worked as expected. I would be happy to revise the snippet if you report otherwise (please provide screenshots). I have tested this code with Storefront theme, the WooCommerce version listed above and a WordPress-friendly hosting on PHP 7+.

If you think this code saved you time & money, please join other Business Bloomer supporters and avail of 365 days of WooCommerce benefits. Thank you in advance :)

Need Help with WooCommerce Customization?

Check out these free video tutorials. You can start learning how to customize WooCommerce without unnecessary plugins. Watch me code and learn by example!

  • how-to-edit-woocommerce-with-php-snippets
  • woocommerce-hooks-add_action-list-visual
  • woocommerce-customize-single-product-page-PHP

Rodolfo Melogli

Author, WooCommerce expert and WordCamp speaker, Rodolfo has worked as a WooCommerce freelancer since 2011. His goal is to help entrepreneurs and developers overcome their WooCommerce nightmares. Rodolfo loves travelling, chasing tennis & soccer balls and, of course, wood fired oven pizza.

21 thoughts on “WooCommerce: Display Order Delivery Date @ Checkout

  1. 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

    1. 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!

  2. Not show delivery date in order view page in backend.

  3. 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.

    1. 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!

  4. Hi Rodolfo,

    Does this snippet still work? I just deployed on my staging website and it does not show up.

    Best regards,
    Ricardo

    1. Yep, it should. Can you try with another theme?

  5. 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

    1. 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

  6. Hey is it possible to set minimum delivery date so I can offer handmade products? So that it’s different with each product

    1. 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

  7. Great snippet! Could it be synched with subscriptions?

    1. 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

  8. Hello Friend. Thanks for the snippet, it works great!
    Q: Is there an option to add the delivery date to your order email?

    1. 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

  9. 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?

    1. Hey Mike, yes that could be done – but you need to make the two systems “talk” with additional PHP ๐Ÿ™‚

  10. Thanks Rodolfo for your wonderful mega snippet! This would a super time saver for many others. ๐Ÿ˜‰

  11. Thanks for your tutorials. Today my PM required me to implement this function for our client’s website.
    Much appreciate!

Questions? Feedback? Support? Leave your Comment Now!
_____

If you are writing code, please wrap it between: [php]code_here[/php]. Failure to complying with this (as well as going off topic) will result in comment deletion. You should expect a reply in about a week - this is a popular blog but I need to get paid work done first. Please consider joining #BloomerArmada to ask me 1-to-1 WooCommerce questions. Thank you :)

Your email address will not be published. Required fields are marked *