doufu3718 2019-04-01 11:23
浏览 47
已采纳

如何在结账后计算订单总额

I have calculated a different custom order total in Woocommerce:

add_action( 'woocommerce_checkout_create_order', 'change_total_on_checking', 20, 1 );
function change_total_on_checking( $order ) {
    // Get order total
    $total = $order->get_total();

    $orderproduct = $order->get_items();
    $tax_rate     = WC_Tax::get_rates( $orderproduct );

    if ($tax_rate == "10") {
        $percent10 = $total * $tax_rate; 
    }

    if ( $tax_rate == "4" ){
        $percent4 = $total * $tax_rate;
    }

    ## -- fai check e calcoli -- ##
    $new_total = $total + $percent4 + $percent10; // <== Fake calculation

    // imposta un calcolo nuovo
    $order->set_total( $new_total );
}

But my calculations don't work and I'm not able to make it for instance.

Any advice or help please?

  • 写回答

3条回答 默认 最新

  • doupeng8419 2019-04-01 14:06
    关注

    Is there ever a time you would have both tax rates? Otherwise, I would think one variable for taxes would be enough, like so:

    if ($tax_rate == "10") {
        $tax_total = $total * $tax_rate; 
    }
    
    if ( $tax_rate == "4" ){
        $tax_total = $total * $tax_rate;
    }
    
    ## -- fai check e calcoli -- ##
    $new_total = $total + $tax_total
    

    Also, what do you mean your calculations are working?

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥30 关于用python写支付宝扫码付异步通知收不到的问题
  • ¥50 vue组件中无法正确接收并处理axios请求
  • ¥15 隐藏系统界面pdf的打印、下载按钮
  • ¥15 MATLAB联合adams仿真卡死如何解决(代码模型无问题)
  • ¥15 基于pso参数优化的LightGBM分类模型
  • ¥15 安装Paddleocr时报错无法解决
  • ¥15 python中transformers可以正常下载,但是没有办法使用pipeline
  • ¥50 分布式追踪trace异常问题
  • ¥15 人在外地出差,速帮一点点
  • ¥15 如何使用canvas在图片上进行如下的标注,以下代码不起作用,如何修改