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

How to Set a Minimum Shipping Cost for WooCommerce Shipping Methods?

Setting up minimum shipping cost customization will let you to replace the shipping costs for the methods which is less than the defined minimum amount. Regardless of the initial cost set for the shipping methods, the code ensures it meets the defined minimum cost uniformly applying for all shipping methods.

add_filter('woocommerce_package_rates', 'ts_custom_shipping_costs', 20, 2);

function ts_custom_shipping_costs($rates, $package) {
    // New minimum shipping cost
    $minimum_cost = 10;

    foreach ($rates as $rate_key => $rate) {
        // Excluding free shipping methods
        if ($rate->method_id !== 'free_shipping') {
            // Set minimum rate cost
            $rates[$rate_key]->cost = max($minimum_cost, $rates[$rate_key]->cost);
        }
    }

    return $rates;
}

Output

This is how the cost of Flat rate and local pickup shipping methods are assigned.

How to Set a Minimum Shipping Cost for WooCommerce Shipping Methods? - Tyche Softwares
How to Set a Minimum Shipping Cost for WooCommerce Shipping Methods? - Tyche Softwares

once the code is implied you can see that the cost of a flat rate which is less than the defined amount gets changed . If the shipping cost is greater than the defined amount then the cost remains unchanged.

How to Set a Minimum Shipping Cost for WooCommerce Shipping Methods?

Alternatively, want to set a maximum shipping cost based on shipping zone? This post guides you well to set maximum shipping cost based on delivery country in WooCommerce which will dynamically adjusts shipping rates for all methods.

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