Halloween Sale 15% off Ends in See the plans
PHP

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

Don’t have WPIDE yet? Install it on your site

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

  1. Install WPIDE on your WordPress site (it is free) and open Code Snippets.
  2. Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
  3. It is added inactive: review the code and settings, then switch it on.

Have a snippet worth sharing?

Publish it to the library from WPIDE or right here. Sign in with any WordPress site that runs WPIDE, free or Pro. Public snippets are reviewed by the WPIDE team before they appear.

Which site should get this snippet?

Enter the address of your WordPress site. WPIDE opens there in a new tab with the snippet ready to review and save.

Remembered in this browser only, so you are asked once.

Report this snippet

Tell the WPIDE team what is wrong: broken code, something harmful, spam or copied work.