Hello @afoc,
Thank you for your message.
We’ll work on this, so I’ll let you know when we’ll provide this feature.
Best regards,
Marta
Thread Starter
afoc
(@afoc)
Ok, thank you for the quick response.
Here’s a code snippet you could add to your functions.php or create a plugin with the following:
You’ll need to see which UPS methods you use to find the IDs.
// Hat tip: https://gist.github.com/xadapter/c91282b9e1df7623085745fd9008bf1c
add_filter( ‘woocommerce_package_rates’, function( $shipping_costs) {
$shipping_method_min_cost = array(
// Shipping id => min_cost
‘ups:1:03’ => 11,
‘ups:1:12’ => 11,
‘ups:1:02’ => 11,
‘ups:1:13’ => 11,
‘ups:1:1’ => 11,
);
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;
});
Thread Starter
afoc
(@afoc)
Thanks @dlim_vernier, that was helpful.
The IDs can be checked by echoing the contents of $package['rates']
in plugins/woocommerce/includes/class-wc-shipping.php
, which is where the woocommerce_package_rates
filters are applied.
I found that the method IDs on my local environment are named like this: flexible_shipping_ups:2:01
, etc, but they weren’t the same for the production environment. I ended up doing the following & setting a minimum no matter what method is used.
add_filter( 'woocommerce_package_rates', function( $shipping_costs, $package ) {
$shipping_min_cost = 15;
foreach( $shipping_costs as $shipping_cost ) {
$shipping_method_id = $shipping_cost->get_id();
$cost = (float) $shipping_cost->get_cost();
if( $cost < $shipping_min_cost ) {
$shipping_cost->set_cost($shipping_min_cost);
}
}
return $shipping_costs;
}, 1, 2);
@afoc
Thanks afoc..
I use this snippet for some months now, but I saw some days ago that the amount of the VAT on the shipping cost is calculate on the previous value.
Any idea why?
Thanks
Example:
Total = 119
UPS = 9.88 (the minimum value)
Tax (20%) = 25.57 – I must have 25.78
Total = 154.45 – I must have 154.66
add_filter( 'woocommerce_package_rates', function( $shipping_costs, $package ) {
// Bellow minimum cost:
$shipping_min_cost = 9.88;
foreach( $shipping_costs as $shipping_cost ) {
$shipping_method_id = $shipping_cost->get_id();
$cost = (float) $shipping_cost->get_cost();
// 2 lines bellow added by Remi:
$cost = $cost*1.11;
$shipping_cost->set_cost($cost);
if( $cost < $shipping_min_cost ) {
$shipping_cost->set_cost($shipping_min_cost);
}
}
return $shipping_costs;
}, 1, 2);