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;
}
@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