Black Friday & Cyber Monday SUPER SALE ALL WEEK:
Grab 40% OFF on plugins
Days
Hours
Minutes
Seconds

How to Set All Shipping Methods’ Costs to Zero Based on Cart Total Amount in WooCommerce?

An easy solution to adjust the displayed shipping costs as”free” when the cart total is greater than or equal to a certain amount by using this handy code snippet given below.

function ts_filter_woocommerce_package_rates( $rates, $package ) {
    // Cart total amount (integer)
    $cart_total = WC()->cart->cart_contents_total;

    // Greater than or equal to
    if ( $cart_total >= 59.99 ) {
        foreach ( $rates as $rate_key => $rate ) {
            // For "free shipping" method, do not remove it
            if ( $rate->method_id != 'free_shipping' ) {
                // Append rate label titles (free)
                $rates[$rate_key]->label .= ' ' . __( '(free)', 'woocommerce' );

                // Set rate cost
                $rates[$rate_key]->cost = 0;

                // Set taxes rate cost (if enabled)
                $taxes = array();

                foreach ( $rates[$rate_key]->taxes as $key => $tax ) {
                    if ( $rates[$rate_key]->taxes[$key] > 0 ) {
                        $taxes[$key] = 0;
                    }
                }

                $rates[$rate_key]->taxes = $taxes;
            }
        }
    }

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

Output

The output shows that the label of shipping option costs are replaced as ‘free’ when the cart total is greater than or equal to $59.99.

How to Set All Shipping Methods' Costs to Zero Based on Cart Total Amount in WooCommerce? - Tyche Softwares

Additionally, you can set all shipping methods cost to zero for a free shipping coupon in WooCommerce where this feature is especially useful in clearance sale offering both free shipping and coupon discounts.

Browse more in: Code Snippets, WooCommerce How Tos, WooCommerce Tutorials

Share It:

Subscribe
Notify of
0 Comments
Newest
Oldest
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x
Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible.

Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.

By using our site, you acknowledge that you have read and understood our Privacy Policy and Terms & Conditions.