How to discount shipping costs over a certain spend

Offering free shipping is the best way to encourage shoppers to spend more money in your store, but some products just don’t have enough profit margin to make that possible. Nevertheless, you might still want to offer a shipping cost discount to high-spending customers.

There are, of course, table rate shipping plugins that can do this task quite easily. But if you don’t want to switch to a different (probably expensive) shipping rate plugin, or are content to use WooCommerce’s built-in shipping rate functionality, it’s actually quite easy to add shipping discount rules with a little bit of code.

function launchwoo_adjust_shipping_rate( $rates ) { 

    $cart_subtotal = WC()->cart->subtotal; 
 
    // Check if the subtotal is greater than value specified 
    if ( $cart_subtotal >= 99 ) { 
    
        // Loop through each shipping rate 
            foreach ( $rates as $rate ) { 
 
                // Store the previous cost in $cost 
                $cost = $rate->cost; 
 
                // Discount rate by $10 
                // This is the most we're prepared to give away free 
                $rate->cost = $cost - 10; 
                                 
                //Ensure no negative values are passed 
                    if ($rate->cost < 0) { 
                        $rate->cost = 0; 
                    } 
                } 
        } 
         
        return $rates; 
} 
add_filter( 'woocommerce_package_rates', 'launchwoo_adjust_shipping_rate', 10 );

The below code checks whether the cart subtotal is greater than $99, and if it is, it knocks a flat $10 off the shipping cost. You can also do percentage discounts by replacing the subtraction with a multiplication—for example “$cost * 0.5” to discount shipping by 50%.

To use this code, just add it to your theme’s Functions.php file or to a MU Plugin.

Advanced: If you want to be very clever, you can have multiple cart subtotal checking conditionals to apply different discount levels. Maybe knock a further $10 off if the customer spends over $200, for instance. You can also go the other way and charge more shipping if the customer spends under a certain amount.

Shane Gowland

Hi! I’m a web designer, software developer, and digital marketer based in South Australia. I've been building websites on WordPress for over 12 years. You can learn more about the projects and businesses I'm involved with on my website.

Leave a Reply