How to Offer Free Shipping in WooCommerce for Orders Over a Certain Amount

If you run an online store, you may want to offer free shipping to your customers for orders over a certain amount. This can be a great way to incentivize larger purchases and boost sales. In this article, we’ll show you how to use a simple code snippet to offer free shipping in WooCommerce for orders over a certain amount.

Step 1: Add the Function to Your Functions.php File

To get started, you’ll need to add the following code to your functions.php file or a custom plugin:

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

function wp_daily_rates( $rates, $package ) {
	$subtotal  = WC()->cart->subtotal;
	$freeValue = 50; //change the value to fit your needs
	
	$condition = $subtotal >= $freeValue;
	$free      = array();
	
	foreach ( $rates as $rate_key => $rate ) {
		
		if ( !$condition ){
			if( 'free_shipping' === $rate->method_id  ) {
				unset($rates[$rate_key]);
			}
		}
		elseif ( 'free_shipping' === $rate->method_id ) {
			$free[$rate_key] = $rate;
		}
	}
	
	return !empty( $free ) && $condition ? $free : $rates;
}

This code will check the cart subtotal and remove the free shipping option if the subtotal is below a certain amount. In this case, the amount is set to $50, but you can change it to fit your needs.

However, before this code can work, you need to enable the free shipping option in WooCommerce. To do this, go to WooCommerce > Settings > Shipping > Shipping Zones > Your Shipping Zone and click on the “Edit” button next to “Free shipping.” Make sure the “Enable this shipping method” checkbox is checked.

Step 2: Set the Free Shipping Subtotal Value

In the wp_daily_rates function code, you need to set the value of $freeValue to the minimum order subtotal required to qualify for free shipping. For example, if you want to offer free shipping on orders with a subtotal of $50 or more, you would set $freeValue to 50.

Step 3: Customize the Free Shipping Offer

You can customize the free shipping offer by changing the code in the foreach loop. By default, the code will remove the free shipping option if the order subtotal is below the minimum value set in $freeValue. If the order subtotal is above the minimum value, the free shipping option will be added to the available shipping options.

Step 4: Test the Function

Note: It’s important to note that any items in the cart before enabling free shipping will not update automatically. You will need to remove the items from the cart and re-add them for the free shipping option to take effect.

Once you’ve enabled free shipping and added the code snippet to your site, your customers will automatically be offered free shipping on orders over the specified amount. This can be a great way to incentivize larger purchases and boost sales.

Leave a Comment

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