0

I'm trying to give tax exempt status to user on checkout by having them hit yes on radio button and then upload their tax exempt docs.

I got the radio and file upload working but can't seem to have it update the tax amount on the checkout page.

And I saw this solution Add Tax Exempt form on checkout in woocommerce and tried altering to match my set up but it's not working. PHP is not my strong suit, so I'm sure I messed up somewhere.

Part that I'm having the issue with. It's not updating the tax.

add_action( 'woocommerce_checkout_update_order_review', 'taxexempt_checkout_update_order_review');
function taxexempt_checkout_update_order_review( $post_data ) {
  global $woocommerce;

  $woocommerce->customer->set_is_vat_exempt(false);

  parse_str($post_data);

  if ( isset($uhave_tax_exempt) && $uhave_tax_exempt == '1')
    $woocommerce->customer->set_is_vat_exempt(true);                
}

Part that is working to display radio button and file upload.

function add_radio_field(){
    $radioFile   = "";
    $radioFile   .='<div class="customfield_cover"><label for="some_field_name" class="">Tax Exempt? </label><div id="radio_cover_id">';
    $radioFile .='<input name="uhave_tax_exempt" class="tax_exempt" type="radio" value="1" >Yes&nbsp;&nbsp;&nbsp;&nbsp;<input class="tax_exempt" name="uhave_tax_exempt" type="radio" value="2" >No';
    $radioFile .='</div></div>';
    echo $radioFile;
 }
add_action('woocommerce_before_order_notes','add_radio_field');

function add_file_field(){
     $uploadFile   = "";
     $uploadFile   .='<div class="customfield_cover custom_file_upload_cvr" style="display:none;" >
     <label for="some_field_name" class="">Attach tax exempt / Resale certificate </label>
     <div id="upload_CNIC_image" style="position:relative;left:15px;">';
     $uploadFile .='<input id="custom_file_upload" name="tax_exempt_attachmentfile" accept="file_extension|image/*|application/pdf|application/msword" type="file"  multiple="true" />
     <input type="hidden" value="" name="uploaded_docs" id="uploaded_docs" />
     <input type="hidden" value="" name="uploaded_docs_org" id="uploaded_org" />
     <div class="remove_uploaded"></div>
     ';
     $uploadFile .='</div></div>';
     echo $uploadFile;
 }
add_action('woocommerce_before_order_notes','add_file_field');
Ollie
  • 1
  • 1

1 Answers1

0

Might not fully solve the situation but $woocommerce->customer->set_is_vat_exempt(FALSE); will not work as the boolean values in PHP are all lower case so I would replace this line with $woocommerce->customer->set_is_vat_exempt(false);

Neil Clayton
  • 146
  • 7