0

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?

Zain Sohail
  • 464
  • 5
  • 22
  • `woocommerce_get_fee()` doesn't exist and `$booking_id` is not defined… As you are removing all fees items, how can you get any fees just after using `woocommerce_get_fee( $booking_id );`? Why are you setting taxes in fees? Your code seems really weird (and should always comment it)... – LoicTheAztec Jul 16 '18 at 07:08
  • Fixed my code, hope its more clear now – Zain Sohail Jul 17 '18 at 07:57

0 Answers0