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.

2 thoughts on “How to discount shipping costs over a certain spend”

  1. Hello
    I want simultary code.
    Over 15€ up to 2 pcs quantity shipping discount 50%
    Over 50€ up to 3 pcs 100% discount
    You can help me?

    • Hi Baz, you’ll want to use WC()->cart->get_cart_contents_count();

      So up the top, create a variable that’s like:
      $cart_quantity = WC()->cart->get_cart_contents_count();

      Then in the conditional, include a check for quantity as well. For example
      if ( $cart_subtotal >= 99 ) && ($cart_quantity > 3) {
      //Discount the rate.

      I hope this helps to point you in the right direction.


Leave a Reply