WooCommerce为购物车增加了不可征税的费用和折扣,可以计算错误的税额



我有一个WooCommerce网站,产品可能有可纳税的存款费,可能有送货费(7.50美元),并且可能有折扣。不应用负费费(折扣)正确计算税款。一旦我添加了负费用,税款包括其计算中的非税款存款费。我读到某个地方不建议您进行负费用。我也找到了这篇文章,但不知道这是否适用。是否有另一种方法可以在购物车中完成此操作,并在订单,电子邮件等中显示?仅供参考,税率为15%。这是我正在使用的代码:

function woocommerce_custom_fees( $cart ) {
    if ( is_admin() && ! defined( 'DOING_AJAX' ) )
        return;
    // Loop through cart items
    foreach ( $cart->get_cart() as $cart_item ) {
        $item_data = $cart_item['data'];
        $deposit = $item_data->get_attribute('deposit');
        $delivery = $cart_item['delivery'];
        if ( $deposit ) {
            $total_deposit += $cart_item['quantity'] * $deposit;
        }
        if ( $delivery == 'deliver' ) {
            $total_delivery += $cart_item['quantity'] * 7.5;
        }
    }
    if ( $total_deposit > 0 ) {
        // non-taxable
        $cart->add_fee( 'Deposit', $total_deposit, FALSE );
    }
    if ( $total_delivery > 0 ) {
        // taxable
        $cart->add_fee( 'Delivery', $total_delivery, TRUE );
    }
    //  test $10 discount
    $cart->add_fee( 'Test discount', -10.00);
}
add_action( 'woocommerce_cart_calculate_fees','woocommerce_custom_fees', 25, 1 );

正确的税额,没有负费用

负费用不正确的税额

更新:我发现此帖子对购物车内容的折扣总额不包括WooCommerce中的税收,该税表示,使用负费用将始终征收税收。除了使用负费用或优惠券外,还有其他方法可以在购物车中应用折扣吗?

function woocommerce_custom_fees( $cart ) {
    if ( is_admin() && ! defined( 'DOING_AJAX' ) )
        return;

        // non-taxable
        $cart->add_fee( 'Deposit', 6, FALSE );

        // taxable
        $cart->add_fee( 'Delivery', 7, TRUE );

    //  test $10 discount
    //$cart->add_fee( 'Test discount', -10.00 , FALSE);
}
add_action( 'woocommerce_cart_calculate_fees','woocommerce_custom_fees', 25, 1 );

add_filter( 'woocommerce_calculated_total', 'discounted_calculated_total', 10, 2 );
function discounted_calculated_total( $total, $cart ){
    $total = $total - 10;
    return $total;
}

尝试过?

最新更新