Woocommerce: Recalculate Tax Information for old orders

Job ID: 34418438

Budget: €12 – €18 EUR

Hi everyone,

we changed the tax information for a lot of our products. Now we have to recalculate taxes for existing orders since 01.01.2021.

We already did that manually for a few orders. However this approach takes way to long because we have thousands of existing orders.

1. Edit corresponding purchase order
2. Set purchase order from "completed" to "on hold
3. Update/Save
4. Now the order can be edited:
5. Check which coupon has been redeemed
6. Remember the product ID of the order
7. Delete product completely
8. Add new product via product ID
9. If voucher was used Add voucher code
10. Update/Save

So we are now looking for a basic WooCommerce function to recalculate tax information for the existing orders based on the new product information.

Can you help us to programme something?

It would be probably a for-loop
foreach ($order->get_items() as $item_id => $item) {
delete product item from order
add updated product item to order again.
}
Related categories: PHP WordPress Software Architecture MySQL WooCommerce