Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wordpress 按订单重新计算商业费用_Wordpress_Woocommerce_Fee - Fatal编程技术网

Wordpress 按订单重新计算商业费用

Wordpress 按订单重新计算商业费用,wordpress,woocommerce,fee,Wordpress,Woocommerce,Fee,我正在尝试创建一个功能,它将删除订单中添加的任何旧费用,并根据订单项目添加新费用。我已经创建了给定的函数 public function order_recalculate_taxes( $order_id ) { global $woocommerce; $order = wc_get_order( $order_id ); // Iterating through order fee items ONLY foreach( $order->

我正在尝试创建一个功能,它将删除订单中添加的任何旧费用,并根据订单项目添加新费用。我已经创建了给定的函数

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, '' );
    }
}

有人能帮我弄清楚吗

woocommerce\u get\u fee()
不存在,并且未定义
$booking\u id
。由于您正在删除所有费用项目,您如何在使用
woocommerce\u get\u fee($booking\u id)后获得任何费用?你为什么要在收费中征税?你的代码看起来真的很奇怪(应该经常注释它)…修复了我的代码,希望现在它更清晰