"Order Within X Hours for Same-Day Dispatch" Notice
Shows a live notice on product pages telling shoppers how long they have left to order for dispatch today, or that orders ship on the next working day.
Opens WPIDE on
Code
add_action( 'woocommerce_single_product_summary', function () {
$cutoff = '14:00'; // Daily dispatch cutoff.
$working_days = array( 1, 2, 3, 4, 5 ); // Days you ship.
global $product;
if ( ! $product instanceof WC_Product || ! $product->is_in_stock() || $product->is_virtual() ) {
return;
}
$now = new DateTime( 'now', wp_timezone() );
$deadline = new DateTime( 'today ' . $cutoff, wp_timezone() );
if ( in_array( (int) $now->format( 'N' ), $working_days, true ) && $now < $deadline ) {
$diff = $now->diff( $deadline );
$text = sprintf( 'Order within %1$dh %2$dm for dispatch today.', $diff->h, $diff->i );
} else {
$text = 'Order now for dispatch on the next working day.';
}
echo '<p class="wpide-dispatch-notice" style="padding:8px 12px;border-radius:4px;background:#f0f6fc;">🚚 ' . esc_html( $text ) . '</p>';
}, 25 );
Notes
Set $cutoff (24h, site timezone) and $working_days (1 = Monday ... 7 = Sunday).
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.