I am trying to create a function which will remove any old fee's added in the order and add new ones based on the order items. I have created the function given be
public function order_recalculate_taxes( $order_id ) {
global $woocommerce;
$order = wc_get_order( $order_id );
// Iterating through order fee items ONLY
foreach( $order->get_items('fee') as $item_id => $item_fee ){
$order->remove_item($item_id);
}
// calculate the new fee according to booking id
// this is a custom function which generates the
// output code give below
$fees = $this->woocommerce_get_fee( $booking_id );
// output: array(1) { [0]=> array(2) { ["name"]=> string(3) "VAT" ["total"]=> float(48.8) } }
foreach ($fees as $fee) {
$order->add_fee( $fee['name'], $fee['total'], true, '' );
}
}
Can anyone help me figure this out?