Offering Free Shipping with UPS WooCommerce Shipping Plugin

Linchpin - Offer free shipping for orders of any amount using UPS WooCommerce Shipping by Plugin Hive

UPS WooCommerce Shipping by PluginHive is a powerful extension that helps you automate UPS shipping by displaying real-time rates on the cart/checkout pages, pay for and print labels from within the admin area, and more. For our clients that ship with UPS, it’s a no-brainer that we always recommend.

But recently we had a request to offer free ground shipping if the cart total is $50.00 or more. Although the plugin does have a “price adjustments” feature that allows you to increase or decrease the actual shipping cost by a certain amount, it doesn’t have the ability to use logic to determine when those adjustments are applied.

Luckily, WooCommerce has some built-in actions and filters that we can utilize to accomplish the goal of offering free shipping when the user is spending more than a certain amount of money.

 

Locating the shipping method ID

Before we can write any code though, we first need to get the ID of the shipping method that we want to modify. You can do this by right-clicking on the shipping method on the checkout page and inspecting the element.

 

Creating a conditional and setting the cost to 0

Now that we know the ID (wf_shipping_ups:03 in this case, but it may be different in yours), we will hook into woocommerce_package_rates and set the cost to $0 if the cart subtotal is at least $50.

 

function lp_free_shipping( $rates, $package ) {
    // Make sure the UPS shipping rate is available.
    if ( isset( $rates['wf_shipping_ups:03'] ) ) {
        // Current value of the shopping cart.
        $cart_subtotal = WC()->cart->subtotal;

        // Check if the subtotal is at least $50.
        if ( 50 >= $cart_subtotal ) {
            // Set the cost to $0.
            $rates['wf_shipping_ups:03']->cost = 0;
        }
    }

    return $rates;
}
add_filter( 'woocommerce_package_rates', 'lp_free_shipping', 10, 2 );

 

Modify the shipping method label

Great! To make it even more clear to the customer that the shipping will be free, we will change the label from “Ground Shipping (UPS)” to “Free Ground Shipping (UPS)” by hooking into the woocommerce_shipping_rate_label filter.

 

function lp_free_shipping_label( $label, $object ) {
    $cart_subtotal = WC()->cart->subtotal;

    // Check if the subtotal is at least $50, and we're editing the correct label.
    if ( 50 >= $cart_subtotal && 'Ground (UPS)' === $label ) {
        $label = esc_html__( 'Free Ground Shipping (UPS)', 'text-domain-here' );
    }

    return $label;
}
add_filter( 'woocommerce_shipping_rate_label', 'lp_free_shipping_label', 10, 2 );

 

And that’s it! The customer will not be charged for UPS ground shipping if their subtotal is at least $50.

You can easily change the logic to fit your specific needs. For example, instead of checking if the subtotal is at least $50, you could check if the cart contains a specific product, has a certain number of items, the customer is shipping to the lower 48 states, etc.

If you’re interested in improving your WooCommerce store, you can always reach out to our team and let us know how we can help you!

Reaady to streamline your visitors' ecommerce check experience with Linchpin?

 

Nate Allen

Nate has a real passion for WordPress, and is especially skilled at building complex plugins that meet a client’s unique needs. He also enjoys mentoring and sharing his knowledge.

| @ncallen