0

Need to add a custom field to the checkout form radio field with two options then disable woocommece tax based on it in option one there is no tax, in option two there is tax normally.

I added the custom field using the “Checkout Field Editor (Checkout Manager) for WooCommerce” plugin

Field name Citizens status and their options are ( Citizen or Non-Citizen)

Now I tried to disable the tax for citizen option and enable it for Non-Citizen

add_filter( 'woocommerce_checkout_fields' , 
'citizens_status_trigger_update_checkout_on_change', 10, 1 );
function citizens_status_trigger_update_checkout_on_change( $fields ) {

    $fields['citizenstatus_']['class'] = 'update_totals_on_change';

    return $fields;
}

add_action( 'woocommerce_checkout_update_order_review', 'checkout_vat_exempt_based_on_citizenstatus', 10, 1 );

function checkout_vat_exempt_based_on_citizenstatus( $post_data ) {
    parse_str($post_data, $results); // Since Php 7.2, the 2nd argument is recommended in parse_str() function
    extract($results);

    $customer = WC()->customer;

    if (  $citizenstatus_ == 'Citzen'  ) {
        $customer->set_is_vat_exempt( false );
    }
    else {
        $customer->set_is_vat_exempt(true);
    }
}

But this code not working, how we can determine the error in it

0 Answers0