WooCommerce: Show Dispatch / Est. Shipping Date @ Single Product

A good way to inform online customers and avoid issues is showing the estimated delivery / dispatch time on the single product page, just below the “Add to Cart” button. Yes, you could do that manually by adding shipping info to each product short description, but the goal of Business Bloomer is to learn how to code that instead, so you won’t need to write things manually.

Also, this is great because if you change something in your dispatch rules, you just need to change the short PHP snippet and not all your product descriptions. It’s much more flexible this way.

Finally, in this post we’ll learn how to work with cut-off times (hour of the day) and current day of the week (pure PHP), so that we can show a “dynamic” notice based on current date. So, let’s see how it’s done!

It’s Monday before 4PM – this snippet is printing a notice just below the single product page add to cart that if I order by 4PM the product will be shipped today!

PHP Snippet: Display Dispatch / Estimated Delivery Date @ Single Product Page

Case scenario:

  • Friday/Saturday/Sunday orders ship on Monday
  • For other days, if before 4PM ships today…
  • …if after 4PM ships tomorrow

Please note the “date(‘N’)” and the “date(‘H’)” functions, which in PHP they respectively give me the current day of the week and current hour of the day so I can compare them with local & current time. Also look into “date_default_timezone_set()” function in case you want to set a different timezone, which is vital for this snippet’s calculations.

/**
 * @snippet       Dispatch Date @ WooCommerce Single Product
 * @how-to        Get CustomizeWoo.com FREE
 * @author        Rodolfo Melogli
 * @testedwith    WooCommerce 3.9
 * @donate $9     https://businessbloomer.com/bloomer-armada/
 */

add_action( 'woocommerce_after_add_to_cart_form', 'bbloomer_dispatch_info_single_product' );
   
function bbloomer_dispatch_info_single_product() {
	date_default_timezone_set( 'Europe/London' );  
	
	// if FRI/SAT/SUN delivery will be MON
	if ( date( 'N' ) >= 5 ) {
		$del_day = date( "l jS F", strtotime( "next monday" ) );
		$order_by = "Monday";
	} 
	
	// if MON/THU after 4PM delivery will be TOMORROW
	elseif ( date( 'H' ) >= 16 ) {
		$del_day = date( "l jS F", strtotime( "tomorrow" ) );
		$order_by = "tomorrow";
	} 
	
	// if MON/THU before 4PM delivery will be TODAY
	else {
		$del_day = date( "l jS F", strtotime( "today" ) );
		$order_by = "today";
	}

	$html = "<br><div class='woocommerce-message' style='clear:both'>Order by 4PM {$order_by} for delivery on {$del_day}</div>";
	
	echo $html;
}

Where to add this snippet?

You can place PHP snippets at the bottom of your child theme functions.php file (delete "?>" if you have it there). 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.3.

If you think this code saved you time & money, feel free to join 14,000+ WooCommerce Weekly subscribers for blog post updates or 250+ Business Bloomer supporters for 365 days of WooCommerce benefits. Thank you in advance :)

Need Help with WooCommerce?

Check out these free video tutorials. You can learn how to customize WooCommerce without unnecessary plugins, how to properly configure the WooCommerce plugin settings and even how to master WooCommerce troubleshooting in case of a bug!

Rodolfo Melogli

Business Bloomer Founder

Author, WooCommerce expert and WordCamp speaker, Rodolfo has worked as an independent 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.

28 thoughts on “WooCommerce: Show Dispatch / Est. Shipping Date @ Single Product

  1. Hi, Rodolfo, I would like to use your snippet in German… I read the Spanish comments, but could not figure out to get a German text on my product pages… Thank you!

    1. Hi Jens! Did you try change the “Order by 4PM {$order_by} for delivery on {$del_day}” string?

  2. How do I show the dates in Spanish?

    1. You mean the date format? Check https://www.php.net/manual/en/function.date.php

  3. how do i change the color of the box from green to possibly black or something?

    1. Hi Victor, 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. What about caching? A JS implementation would be cache-friendly

    1. Not sure I understand

  5. great! i was looking for something like this. thank you.
    unfortunately the message is also displayed if the product is not in stock. how could i solve this?

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

  6. This fragment is fantastic, but it hurts, it does not work for Spain because it cannot be translated.
    You can take a look here:

    To format dates in other languages, you must use the setlocale () and strftime () functions instead of date ().

    Greetings Rodolfo !!

    1. Ok!

  7. hello,
    thank you for the good job you are doing. Can the the js code show date rang like ‘ order today for delivery in 3 – 5 days, date.
    thanks.

    1. Hey Jay, 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!

      1. Hi,
        I am able to figure it out. Thank you all the same for the good work.

        1. Cool!

  8. Hi

    I want to ask, what if I want to tell the customer the lead time like this: please allow 2-3 business days to processing

    I want to put it under the Add to Cart ”button

    tq

    1. Hi Rodolfo how can I implement this rule in a woocommerce in Spanish, the result that I choose as is in English
      thanks.

      1. Did you try changing the text to Spanish inside the snippet?

        1. yes i even replaced
          date_default_timezone_set (‘Europe / London’); by date_default_timezone_set (‘Europe / Madrid’) ;.
          It does not respond, it continues giving months and days in English, also “place your order before 4pm today and receive it today, it is not possible. Thank you for your help.

          1. Oh I see what you mean. You’re talking about date “format”, not Spanish words. Check https://www.php.net/manual/en/function.date.php

            1. Hi Rodolfo,

              First of all, thank you for your great work, information, sharing and caring!

              Again, great snippet! Wouldn’t it be great if you can have a in stock or on backorder dependency build-in?
              Any suggestions how?

              Thanks

              Okke

              1. It’d be great, yes – but unfortunately it’s custom work

                1. Dear Rodolfo,

                  I am a great fan of your site, i used a lot of your work to improve our website.

                  I was able to implement this snippet into our site it is working great, do you have a suggestion to make it compatible with wp-rocket cache?

                  The current problem with it that I have to clear the cache to make the snippet to update.

                  Take care!

                  Pal

                  1. Thanks Pal. If you have dynamic content, then you should exclude single product pages from cache

                    1. Dear Rodolfo. Thank you for your reply. In the meantime I found a workaround. Maybe somebody in the future learn from it. The snippet for me updates two times a day, i set up a cronjob to clear the cache of wp-rocket 1 minute after each update. This way I have cached product pages and the snippet always shows the right time.

                    2. Ah ok cool

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

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

Your email address will not be published.