Thanks, i was able to resolve it by using custom coding. I have used woocommerce session to achieve this.
Jquery part:
$('.vat-removal').on('click',function(e){
if($('.vat-removal').is(':checked')) {
var is_clicked = true;
} else {
var is_clicked = false;
}
$.ajax({
url: ajax_params.ajaxurl,
dataType: "json",
type: 'POST',
data: {
action: 'custom_vat_removal',
'clicked': is_clicked,
},
success: function(data) {
$("[name='update_cart']").removeAttr('disabled');
$("[name='update_cart']").trigger('click');
$('body').trigger('update_checkout');
setTimeout(function() {
$('.popup-message').html(data.html);
}, 1500);
}
});
});
Php part:
function vat_removal_function() {
ob_start();
$clicked = isset($_POST['clicked']) ? ($_POST['clicked']) : false;
$result = false;
$html = '';
if($clicked == 'true') :
WC()->session->set( 'remove_vat', 'yes' );
$html = 'VAT is removed from all products.';
$result = true;
else :
WC()->session->set( 'remove_vat', 'no' );
$result = false;
$html = 'VAT will apply to all products now.';
endif;
ob_get_clean();
$msg = array('response' => $result, 'html' => $html);
echo json_encode($msg);
wp_die();
}
add_action('wp_ajax_custom_vat_removal', 'vat_removal_function');
add_action('wp_ajax_nopriv_custom_vat_removal', 'vat_removal_function');
function extempt_vat_for_chekout( $post_data ) {
WC()->customer->set_is_vat_exempt( false );
$retrive_data = WC()->session->get( 'remove_vat' );
if($retrive_data == 'yes') {
WC()->customer->set_is_vat_exempt( true );
} else if ($retrive_data == 'no') {
WC()->customer->set_is_vat_exempt( false );
}
}
add_action( 'woocommerce_checkout_update_order_review', 'extempt_vat_for_chekout' );
function cart_vat_removal() {
WC()->customer->set_is_vat_exempt( false );
$retrive_data = WC()->session->get( 'remove_vat' );
if($retrive_data == 'yes') {
WC()->customer->set_is_vat_exempt( true );
} else if ($retrive_data == 'no') {
WC()->customer->set_is_vat_exempt( false );
}
}
add_action( 'woocommerce_before_calculate_totals', 'cart_vat_removal' );