• Resolved Avinash Patel

    (@avinashdigitl)


    Hello, in my site, i am trying to create one popup and allow user to remove VAT calculation if they have click on button. I was able to manege display popup and ajax in button/checkbox click. Now need help in terms of how to set value in woocommerce session, and how to disable VAT calculation if some value is set in woocommerce Session.

    The page I need help with: [log in to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
  • Saif

    (@babylon1999)

    Hi there,

    I was able to manege display popup and ajax in button/checkbox click. Now need help in terms of how to set value in woocommerce session, and how to disable VAT calculation if some value is set in woocommerce Session.

    I’m afraid this falls under custom development which is not within scope of support, you can hire a WooExpert to solve this.

    As an alternative, I will recommend you check the following tax exemption extension: https://woocommerce.com/products/woocommerce-tax-exempt-plugin/

    I’m going to leave this thread open for a bit to see if anyone is able to chime in to help you out.

    You can also visit the WooCommerce Facebook Community group or the #developers channel of the WooCommerce Community Slack.

    We’re lucky to have a great community of open-source developers for WooCommerce, and many of our developers hang out there, as well.

    Cheers!

    • This reply was modified 2 years, 1 month ago by Saif.
    Thread Starter Avinash Patel

    (@avinashdigitl)

    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' );
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Disaale VAT if customer has clicked button in popup’ is closed to new replies.