Skip to content

Instantly share code, notes, and snippets.

@xadapter
Last active September 10, 2019 07:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xadapter/c91282b9e1df7623085745fd9008bf1c to your computer and use it in GitHub Desktop.
Save xadapter/c91282b9e1df7623085745fd9008bf1c to your computer and use it in GitHub Desktop.
/**
* Snippet to set minimum shipping cost for individual shipping method.
* Created at : 14 May 2018
* Updated at : 14 May 2018
* PluginHive Plugins : https://www.pluginhive.com/plugins/
* Gist Link : https://gist.github.com/xadapter/c91282b9e1df7623085745fd9008bf1c
*/
add_filter( 'woocommerce_package_rates', function( $shipping_costs) {
$shipping_method_min_cost = array(
'flat_rate:5' => 60, // Shipping id => min_cost
'flat_rate:3' => 80,
'wf_fedex_woocommerce_shipping:FIRST_OVERNIGHT' => 99,
);
foreach( $shipping_costs as $shipping_cost ) {
$shipping_method_id = $shipping_cost->get_id();
if( isset($shipping_method_min_cost[$shipping_method_id]) ) {
$cost = (float) $shipping_cost->get_cost();
if( $cost < $shipping_method_min_cost[$shipping_method_id] ) {
$shipping_cost->set_cost($shipping_method_min_cost[$shipping_method_id]);
}
}
}
return $shipping_costs;
});
@lavalldesign
Copy link

Could you calculate VAT?

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