Skip to content

Instantly share code, notes, and snippets.

@xadapter

xadapter/functions.php

Last active Sep 10, 2019
Embed
What would you like to do?
/**
* 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

This comment has been minimized.

Copy link

@lavalldesign lavalldesign commented Sep 4, 2019

Could you calculate VAT?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.