Last active
September 10, 2019 07:55
-
-
Save xadapter/c91282b9e1df7623085745fd9008bf1c to your computer and use it in GitHub Desktop.
WooCommerce Code Snippet to Set Minimum Shipping cost for individual shipping method. PluginHive Plugins used : https://www.pluginhive.com/product/multiple-carrier-shipping-plugin-woocommerce/, https://www.pluginhive.com/product/woocommerce-ups-shipping-plugin-with-print-label/, https://www.pluginhive.com/product/woocommerce-fedex-shipping-plugi…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Could you calculate VAT?