Black Friday & Cyber Monday SUPER SALE ALL WEEK:
Grab 40% OFF on plugins
Days
Hours
Minutes
Seconds

How to Hide Specific Shipping Method Based on Time of Day in WooCommerce?

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? - Tyche Softwares

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? - Tyche Softwares

Similar to the above functionality, we can also hide WooCommerce shipping methods for certain conditions based on order weight, product total, product quantity, etc.

Browse more in: Code Snippets, WooCommerce How Tos, WooCommerce Tutorials

Share It:

Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x