Site icon Experience Wordpress Developer Online – Design Develop and Maintenance Support

WooCommerce Setup Shipping Rates and Free Shipping for Specific Order Amount

In WooCommerce looking for setup Shipping charge like if Order amount less than specific amount than apply Shipping charge else Free Shipping ?
For example: “For Orders amount up to $100, Shipping charge $5; for orders above $100, Free Shipping”.

Like this possible without using any WooCommerce Shipping plugin? Well, the answer is yes!

Follow below 3 step and it will be done.

1. Setup Shipping Zone

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

2. Setup Shipping Methods

Open each one of the shipping methods you added in Step 1 and rename them / set them up like this:

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

Here’s screenshot of what i setup:

3. PHP Script

Add few lines Php script in your active theme functions.php file by which we want to show only 1 Shipping method on Cart and Checkout page instead of Showing both with radio button selection.

add_filter( 'woocommerce_package_rates', 'wdo_woocommerce_tiered_shipping', 10, 2 );
   
function wdo_woocommerce_tiered_shipping( $rates, $package ) {
   
    $threshold = 100;
    //echo "
";print_r($rates);die("developer test");
    if ( WC()->cart->subtotal > $threshold ) {
	if ( isset( $rates['flat_rate:1'] ) ) unset( $rates['flat_rate:2'] );
    } else {
        if ( isset( $rates['flat_rate:2'] ) ) unset( $rates['flat_rate:1'] );
    }
    return $rates;
}

Note, The unique ID of the two flat rates should look look something like “flat_rate:3“. For more info on how to find it, check here: How to get Flat Rate ID

Exit mobile version