Show Dispatch / Est. Shipping Date @ Single Product

A good way to inform online customers and avoid issues is by 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 the current date. So, let’s see how it’s done!

It’s Monday before 4 PM – this snippet is printing a notice just below the single product page add to cart that if I order by 4 PM 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 4 PM ships today…
  • …if after 4 PM 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
 * @author        PHP - Stackoverflow
 * @testedwith    WooCommerce 3.9

add_action( 'woocommerce_after_add_to_cart_form', 'phpsof_dispatch_info_single_product' );
function phpsof_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 (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 the Storefront theme, the WooCommerce version listed above, and a WordPress-friendly hosting on PHP 7+.

If you think this code saved you time & money, feel free to join 10,000+ WooCommerce Weekly subscribers for blog post updates or 250+ PHP Stackoverflow supporters for 365 days of WooCommerce benefits. Thank you in advance 🙂

Leave a Reply

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