我正在尝试创建一个函数,该函数将删除订单中添加的所有旧费用,并根据订单商品添加新的费用。我已经创建了给定的功能
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, '' );
}
}
有人可以帮我解决这个问题吗?