Woocommerce shipment add tax rate programmatically

56 Views Asked by At

For my Woocommerce shop I try to set a specific tax rate. I have two tax rates in my shop: 9% (low rate) and 21% (high rate). Some products have the low rate and other the high rate.

My problem:

If the customer buy a product with the low rate the same tax is calculated for the shipment.

If the customer buy a product with the high rate the same tax is calculated for the shipment.

But if the customer bought multiple products with different tax rates the lowest tax rate is calculated for the shipment.

What I want: If the customer bought multiple products with different tax rates the highest tax rate must be calculated for the shipment.

I tried

add_filter('woocommerce_checkout_create_order', function($order){
    $activeShipping = $order->get_items('shipping');
    foreach($activeShipping as $shipment){
        $shipment->set_total('10');
        $shipment->calculate_taxes('hoog');
    }
    $order->calculate_totals();
}, 10, 1);

The code triggered the shipping costs but not the tax rate.

Who can help me out with this?

0

There are 0 best solutions below