Add Tax Exempt form on checkout in woocommerce

前端 未结 5 2016
孤独总比滥情好
孤独总比滥情好 2021-01-03 03:14

I am trying to add a form to my checkout page so when a user clicks the \'Tax Exempt\' checkbox, a textbox will popup and ask the user what the Tax Exempt Id number is.

5条回答
  •  一整个雨季
    2021-01-03 03:47

    After a long search I found that there is a method for the cart object called remove_taxes() . So, after setting a user meta for the tax exempt users, this cancels the tax totals.

    function remove_tax_for_exempt( $cart ) {
        global $current_user;
        $ok_taxexp = get_the_author_meta( 'granted_taxexempt', $current_user->ID );
        if ($ok_taxexp){ // now 0 the tax if user is tax exempt
            $cart->remove_taxes();
        }
        return $cart;
    } 
    add_action( 'woocommerce_calculate_totals', 'remove_tax_for_exempt' );
    

提交回复
热议问题