WooCommerce Free Shipping Before A Certain Time

WooCommerce disabled shipping method after a specific time


You’ll need the shipping method radio button value from the shipping method you wish to enable and disable.

How To Implement This Solution?

Simply copy the pre-coded solution to your active theme’s functions.php or preferably the Code Snippets Plugin.

About this Solution

A lot of online stores allow free delivery before a certain time of day depending on the courier used. This guide shows you how you can enable the shipping method, free shipping between midnight and 2PM in the afternoon. After 2PM, the free shipping option is turned off. If you need this solution implemented but between different times, simply the times in the code as necessary. You will need the shipping method radio button value which you can get by using your browser’s develop tools to inspect the radio button li class and grabbing the value. You’ll also need to clear customer sessions by going to Dashboard > WooCommerce > Status > Tools > Clear customer sessions. Because of this, it’s a good idea to implement this solution when there is little traffic on the website as clearing custom sessions will empty their cart.

 * Snippet Name:	WooCommerce disable a shipping method after a certain time. In this case, disable free shipping after 2PM and enable it at midnight.
 * Snippet Author:	ecommercehints.com

add_filter( 'woocommerce_package_rates', 'ecommercehints_enable_shipping_method_based_on_coupon', 10, 2 );

function ecommercehints_enable_shipping_method_based_on_coupon($rates, $package) {
$current_time = date("h:i a");
$begin = "2:00 pm";		// Disable the shipping method after this time
$end   = "11:59 pm";	// Enable the shipping method after this time

$date1 = DateTime::createFromFormat('H:i a', $current_time);
$date2 = DateTime::createFromFormat('H:i a', $begin);
$date3 = DateTime::createFromFormat('H:i a', $end);

if ($date1 > $date2 && $date1 < $date3) {
     unset( $rates['free_shipping:14'] ); // The shipping method radio button value
return $rates;  

How Can I Get The Shipping Method Radio Button Value?

Use your browser’s dev tools to inspect the radio button and grab the value from the li class as shown in the screenshot.

WooCommerce get shipping method radio button value

Snippet Benefits

Introduce urgency by limiting free shipping between certain hours in the day.

WooCommerce Conversion Rate Optimisation (CRO) eBook
100 WooCommerce Conversion Rate Optimisation Tips

Leave a Reply

If you are going to write code in the comments, please wrap it between code tags.

Your email address will not be published. Required fields are marked *

Other Recent Guides

Subscribe To Emails

Get exclusive WooCommerce tips that I only share with email subscribers

Join hundreds of other subscribers