Skip to content

Instantly share code, notes, and snippets.

@ChromeOrange
Created October 13, 2014 00:07
Show Gist options
  • Save ChromeOrange/09b60834d34b6f2c90d8 to your computer and use it in GitHub Desktop.
Save ChromeOrange/09b60834d34b6f2c90d8 to your computer and use it in GitHub Desktop.
Set maximum shipping cost depending on delivery country in WooCommerce - add to theme functions.php
/**
* Set maximum shipping cost depending on delivery country in WooCommerce
*/
add_filter( 'woocommerce_package_rates' , 'woocommerce_set_maximum_shipping_cost', 10, 2 );
function woocommerce_set_maximum_shipping_cost( $rates, $package ) {
/**
* Create an array of countries for a maximum shipping cost
* eg array('US','CA');
* for US and Canada.
*/
$county = array('US');
if ( in_array( WC()->customer->get_shipping_country(), $county ) ) {
foreach( $rates as $rate ) {
// Change 10 to your maximum shipping cost
if( $rate->cost > 10 ) {
$rate->cost = 10;
}
}
}
return $rates;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment