wordpress WooCommerce中的程序化附加费不征税

k5hmc34c  于 2022-11-22  发布在  WordPress
关注(0)|答案(1)|浏览(115)

我添加了以下内容,以创建基于重量的附加费的额外购物车费用,但税不适用于额外费用-我遗漏了什么?
问题站点为http://oldhousestore.co.uk/

代码已创建

add_action( 'woocommerce_cart_calculate_fees', 'shipping_weight_fee', 30, 1 );
function shipping_weight_fee( $cart ) {
    if ( is_admin() && ! defined( 'DOING_AJAX' ) )
        return;

    // Convert cart weight in grams
    $cart_weight = $cart->get_cart_contents_weight() * 1000;
    $fee = 0.00697; // Starting Fee below 1000g

    // Above
    if( $cart_weight > 1000 ){
        for( $i = 1000; $i < $cart_weight; $i += 1000 ){
            $fee +=0.00697;
        }
    }
    // Setting the calculated fee based on weight
    $cart->add_fee( __( 'Energy Surcharge' ), $fee, false );

    // Convert cart weight in grams
    $cart_weight = $cart->get_cart_contents_weight() * 1000;
    $fee = 0.00165; // Starting Fee below 1000g

    // Above
    if( $cart_weight > 1000 ){
        for( $i = 1000; $i < $cart_weight; $i += 1000 ){
            $fee +=0.00165;
        }
    }
    // Setting the calculated fee based on weight
    $cart->add_fee( __( 'Environmental Surcharge' ), $fee, false );
}

**预期:**总税额包括附加费、购物车项目和运费
**观察结果:**总税额仅包括购物车商品和运费

fquxozlt

fquxozlt1#

add_fee的第三个参数设置费用是否应纳税:
WC_Cart::add_fee( $name, $amount, $taxable, $tax_class );
在下面这一行中将其设置为false:$cart->add_fee( __( 'Energy Surcharge' ), $fee, false );
您至少应将其设置为true,并且可能还应提供税分类的名称。

相关问题