Skip to content

Instantly share code, notes, and snippets.

@ChromeOrange
Created October 12, 2014 14:54
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ChromeOrange/56ce4571836429af330d to your computer and use it in GitHub Desktop.
Save ChromeOrange/56ce4571836429af330d to your computer and use it in GitHub Desktop.
Set a maximum shipping cost for WooCommerce, add this to functions.php - works with all shipping methods
/**
* Set maximum shipping cost in WooCommerce
*/
add_filter( 'woocommerce_package_rates' , 'woocommerce_set_maximum_shipping_cost', 10, 2 );
function woocommerce_set_maximum_shipping_cost( $rates, $package ) {
foreach( $rates as $rate ) {
// Change 10 to your maximum shipping cost
if( $rate->cost > 10 ) {
$rate->cost = 10;
}
}
return $rates;
}
@prdpetri
Copy link

When i add this to the functions.php my whole site goes blank.
i add the code to the functions.php of my theme, is that correct?

@graficacreoadv
Copy link

I have added the code in wc-deprecated-functions.php (woocommerce --> includes) and it works perfectly

@paenser
Copy link

paenser commented Oct 29, 2015

Thanks!

@julierachlin1
Copy link

Three years after you posted this, here I am looking for the solution. I added to wc-deprecated-functions.php (woocommerce --> includes) and it works great. Thank you!

@skoldin
Copy link

skoldin commented Jan 22, 2018

The taxes will not be calculated correctly for shippings with the actual rate higher than the max rate set.

@siteworkscollab
Copy link

I just added this today and it's still working. Thanks a lot! :)

@mariomax
Copy link

mariomax commented Apr 6, 2020

Thank you. This works perfectly for what we needed. Selling handmade cotton masks and trying not to gouge for shipping.

@carlosrudriguez
Copy link

Worked perfectly for me using WooCommerce 4.7.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment