在WooCommerce中将购物车费用设为零税率 [英] Set a Zero tax rate on a cart fee in WooCommerce

查看:183
本文介绍了在WooCommerce中将购物车费用设为零税率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在woocommerce中,我使用以下代码添加基于产品类别的累进费用(此

In woocommerce I am adding progressive fee based on product categories with the code below (from this answer thread) and it works well:

add_action( 'woocommerce_cart_calculate_fees', 'wc_custom_surcharge', 20, 1 );
function wc_custom_surcharge( $cart ) {
    if ( is_admin() && ! defined( 'DOING_AJAX' ) )
        return; // Exit

    ## Your Settings (below) ##

    $categories      = array(19);
    $targeted_states = array('FL');
    $base_rate       = 1;

    $user_state = WC()->customer->get_shipping_state();
    $user_state = empty($user_state) ? WC()->customer->get_billing_state() : $user_state;
    $surcharge  = 0; // Initializing

    // If user is not from florida we exit
    if ( ! in_array( $user_state, $targeted_states ) )
        return; // Exit

    // Loop through cart items
    foreach ( $cart->get_cart() as $cart_item ) {
        if ( has_term( $categories, 'product_cat', $cart_item['product_id'] )  ){
            // calculating fee based on the defined rate and on item quatinty
            $surcharge += $cart_item['quantity'] * $base_rate;
        }
    }

    // Applying the surcharge
    if ( $surcharge > 0 ) {
        $cart->add_fee( __("State Tire Fee", "woocommerce" ), $surcharge, FALSE, '' );
}

我的问题是我想将此费用设置为不征税.

我已经尝试了几个代码和其他东西,但只是不明白.

I have tried severals codes and things but just don't get it.

任何帮助或追踪都将不胜感激.

Any help or track will be really appreciated.

推荐答案

对于WC_Cart方法 1)免税:将费用设置为免税" (将第三个参数设置为false):

$cart->add_fee( __("State Tire Fee", "woocommerce" ), $surcharge, false );


2)使用零税率"征税:使用零税率" 税种将费用设置为应税" .


2) Taxable with "Zero rate": Set the fee as "taxable" using a the "Zero Rate" tax class.

在这种情况下,您需要在Woocommerce Tx设置中将税率设置为零(如果尚未完成):

In this case you need to set (if not done yet) a zero tax rate in Woocommerce Tx settings:

然后,您将可以在WC_Cart方法add_fee()中设置应税费用,并将第4个参数设置为零费率" ,这是一种税收类别,通过这种方式:

Then you will be able to set in the WC_Cart method add_fee() a taxable fee with the 4th argument set to "Zero rate" which is the tax class, this way:

$cart->add_fee( __("State Tire Fee", "woocommerce" ), $surcharge, true, 'zero-rate' );

其中一个应该起作用.

这篇关于在WooCommerce中将购物车费用设为零税率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆