The new shipping zone management that was introduced with Woo 2.6 gives us the chance to add flat rate, free shipping and local pick-up methods by default.

But what if a client requires 3 different rates depending on the order amount (tiered shipping)? For example: “For orders up to $100, shipping = $5; for orders up to $250, shipping = $2; for orders above $500, shipping = free”.

Is this possible without using a plugin? Well, the answer, as usual, is absolutely yes!

1. Tiered Shipping – Shipping Zone Setup

Go to WooCommerce > Settings > Shipping and create your shipping zone. In the example, I will target US customers and add 3 shipping methods to it: Flat Rate, Flat Rate and Free Shipping.

Shipping Zone Setup for Tiered Shipping
Shipping Zone Setup for Tiered Shipping Shipping Zone Setup for Tiered Shipping

2. Tiered Shipping – Shipping Methods Setup

Open each one of the shipping methods previously added to the zone and rename them / set them up like this:

  1. Flat Rate #1 > rename to “Orders Below $100” and assign cost = $5
  2. Flat Rate #2 > rename to “Orders Below $250” and assign cost = $2
  3. Free Shipping > select “Requires a minimum order amount” = $500

Here’s one of the method’s setup:

Shipping Method Setup for Tiered Shipping
Shipping Method Setup for Tiered Shipping Shipping Method Setup for Tiered Shipping

3. Tiered Shipping – PHP Snippet

Now we need to “tell” WooCommerce that, based on the order amount, a Flat Rate should be used instead of the other. Only in this way we can show the correct shipping method to the end user.

First, take a note of the unique ID of the two flat rates. They should look look something like “flat_rate:9“. For more info on how to find it, check here: https://businessbloomer.com/woocommerce-disable-free-shipping-if-cart-has-shipping-class/#woocommerce-how-to-find-shipping-method-id-woo-2-6-after-the-introduction-of-the-new-shipping-zones

Second, let’s code! We’ll need to “unset” flat rate #2 if we are under $100, otherwise we’ll require to “unset” flat rate #1.


/**
* @snippet       Tiered Shipping Rates | WooCommerce
* @how-to        Get CustomizeWoo.com FREE
* @sourcecode    https://businessbloomer.com/?p=21425
* @author        Rodolfo Melogli
* @testedwith    WooCommerce 3.5.2
* @donate $9     https://businessbloomer.com/bloomer-armada/
*/

add_filter( 'woocommerce_package_rates', 'bbloomer_woocommerce_tiered_shipping', 10, 2 );
  
function bbloomer_woocommerce_tiered_shipping( $rates, $package ) {
  
	$threshold = 100;
	
	if ( WC()->cart->subtotal < $threshold ) {
   		unset( $rates['flat_rate:1'] );
	} else {
		unset( $rates['flat_rate:2'] );
	}
  
	return $rates;
  
}

Share:

Leave a Reply