Hide Express Shipping After the Daily Cut-Off
Removes your next-day or express shipping option after a set time and at weekends, so customers are not promised a delivery you cannot dispatch.
Opens WPIDE on
Code
$wpide_express = array(
'rate' => 'flat_rate:4', // Method ID or rate ID of the express option.
'cutoff' => '14:00', // Last order time (24h).
'weekends' => false, // Offer express at weekends.
);
add_filter( 'woocommerce_package_rates', function ( $rates ) use ( $wpide_express ) {
$now = current_time( 'H:i' );
$weekend = (int) current_time( 'N' ) >= 6;
if ( $now < $wpide_express['cutoff'] && ( $wpide_express['weekends'] || ! $weekend ) ) {
return $rates;
}
foreach ( $rates as $id => $rate ) {
if ( $id === $wpide_express['rate'] || $rate->get_method_id() === $wpide_express['rate'] ) {
unset( $rates[ $id ] );
}
}
return $rates;
}, 20 );
add_filter( 'woocommerce_cart_shipping_packages', function ( $packages ) {
foreach ( $packages as $i => $package ) {
$packages[ $i ]['wpide_hour'] = current_time( 'Y-m-d H' );
}
return $packages;
} );
Notes
Uses the site's timezone, and rates refresh every hour so the option disappears on time for open carts.
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.