Does your store want to offer a specific shipping option to be available only after a certain time of the day(e.g. after 4 PM)? This code will be useful for stores that need time to prepare orders for pickup and want to ensure that customers can only choose this option during specific hours.
add_filter( 'woocommerce_package_rates', 'ts_hide_shipping_method_based_on_time', 10, 2 ); function ts_hide_shipping_method_based_on_time( $rates, $package ) { // Set your default time zone (http://php.net/manual/en/timezones.php) date_default_timezone_set('Asia/Kolkata'); // Set the timezone to India Standard Time (IST) // Here set your shipping rate Id $shipping_rate_id = 'local_pickup:6'; // When this shipping method is available and after 4 PM if ( array_key_exists( $shipping_rate_id, $rates ) && date('H') > 16 ) { unset( $rates[$shipping_rate_id] ); // remove it } return $rates; }
Output
As specified in this code, the ‘Local Pickup’ shipping method will be hidden if the customer is checking out before 4PM. Adjusting the condition date('H') >=
4 allows for customization of the time after which the ‘Local Pickup’ method becomes available during the checkout process.
![How to Hide Specific Shipping Method Based on Time of Day in WooCommerce? 1 How to Hide Specific Shipping Method Based on Time of Day in WooCommerce? - Tyche Softwares](https://media.tychesoftwares.com/wp-content/uploads/hide-shipping-based-on-time-of-the-day-1024x936.png)
The local pickup option is available for customers only after 4PM, since the time is specified in the code.
![How to Hide Specific Shipping Method Based on Time of Day in WooCommerce? 2 How to Hide Specific Shipping Method Based on Time of Day in WooCommerce? - Tyche Softwares](https://media.tychesoftwares.com/wp-content/uploads/SHOWS-LOCAL-PICKUP-1024x600.png)
Similar to the above functionality, we can also hide WooCommerce shipping methods for certain conditions based on order weight, product total, product quantity, etc.