首页 文章

在Woocommerce中为总计添加一个百分比

提问于
浏览
1

在Woocommerce我使用的是Woocommerce One Page Checkout插件,我想在Grand Total上添加10%的消费税 .

这是一个例子(Grand Total上没有10%的消费税):

Cart Total: $200
Delivery charges: $20
Grand Total: $220

结果应该看起来(总计10%的消费税):

Cart Total: $200
Delivery charges: $20
Grand Total: $242 (including 10% of cart total + 10% on Delivery)

在产品列表页面上,这是我做的总计我想要的:

$woocommerce->cart->total = $woocommerce->cart->total + number_format(($woocommerce->cart->total * 10) /100, 2);

问题在于,当我下订单时,我在支付页面上总计220美元而不是242美元 .

如何在此处更新订单总额?
有没有什么方法可以在Woocommerce的总购物车数量上获得10%的消费税?

Note: 我尝试使用网络电话进行调试,发现Woocommerce正在发送包含所有产品的购物车数组,订单页面可能会再次计算总数,不包括我使用上面代码块应用的GST .

1 回答

  • 2

    以下代码将为总计增加10%:

    add_filter( 'woocommerce_calculated_total', 'custom_cart_grand_total', 20, 2 );
    function custom_cart_grand_total( $total, $cart ) {
        return $total * 1.10;
    }
    

    代码位于活动子主题(或活动主题)的function.php文件中 . 经过测试和工作 .

相关问题