cosmin Posted April 4, 2019 Share Posted April 4, 2019 In my country is mandatory to have VAT ID on invoices, so, how can I make the field TAX ID required? I think I have to use a hook. Manythanks! 0 Quote Link to comment Share on other sites More sharing options...
lkitching Posted April 4, 2019 Share Posted April 4, 2019 I am not sure if this is what you are looking for - but figured it might be helpful, on this page: https://docs.whmcs.com/Tax/VAT under "Automatic VAT Number Validation" - if you set the field up and make it a required field they will need to fill it in when that shows as part of the signup process. Hope that helps anyway! 👍 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted April 4, 2019 Share Posted April 4, 2019 (edited) On 04/04/2019 at 13:55, cosmin said: In my country is mandatory to have VAT ID on invoices, so, how can I make the field TAX ID required? I think I have to use a hook. if you're talking about making the tax ID field on the checkout form required for everyone, then you could the following hook... <?php # Make Field Required @ Checkout Hook # Written by brian! use App; add_hook('ShoppingCartValidateCheckout', 1, function ($vars) { $taxcode = App::getFromRequest('tax_id'); if (!$taxcode) { return Lang::trans('clientareaerrortaxid'); } }); there are two options with this - as above, the hook will use a language string in the error output, so you would need to create a Language Override for each language that your site uses... $_LANG['clientareaerrortaxid'] = "You did not enter your Tax ID"; the other way, and more applicable if your site only uses one language, would be to code the string in the hook instead of using language overrides... return 'You did not enter your Tax ID'; if you only need this field requirement for one country, e.g Romania, then you could use... <?php # Make Field Required @ Checkout Hook # Written by brian! use App; add_hook('ShoppingCartValidateCheckout', 1, function ($vars) { $taxcode = App::getFromRequest('tax_id'); $country = App::getFromRequest('country'); if (!$taxcode && $country === 'RO') { return Lang::trans('clientareaerrortaxid'); } }); if this needs to apply to more than a few countries, then i'd suggesting creating an array of applicable 2-letter ISO codes for those countries and using in_array in the if statement. one other change that you might need to make is to remove the (Optional) from the form field - you can't really change it using overrides because the ( and ) are hardcoded in the template and not in the override string (crazy!), so you may need to edit the templates checkout.tpl and/or clientregister.tpl talking of client register, if you need the field required in there too, it might be easier to edit the template because the required fields in that form have the required setting in each applicable <input> field, .e.g., <input type="text" name="tax_id" id="inputTaxId" class="field" placeholder="{lang key=\WHMCS\Billing\Tax\Vat::getLabel()}" value="{$clientsdetails.tax_id}"{if $loggedin} readonly="readonly"{else} required{/if}> Edited June 20, 2019 by brian! 2 Quote Link to comment Share on other sites More sharing options...
cosmin Posted April 5, 2019 Author Share Posted April 5, 2019 With hook from @brian! works perfect. Thank you very much! Thank you also @leewolz for sugestions! 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted April 5, 2019 Share Posted April 5, 2019 20 hours ago, leewolz said: I am not sure if this is what you are looking for - but figured it might be helpful, on this page: https://docs.whmcs.com/Tax/VAT under "Automatic VAT Number Validation" - if you set the field up and make it a required field they will need to fill it in when that shows as part of the signup process. Hope that helps anyway! that should work for older versions which still use custom fields, but later releases which either don't or convert an existing custom field to the new regime, would lose their requirement. 0 Quote Link to comment Share on other sites More sharing options...
lkitching Posted April 5, 2019 Share Posted April 5, 2019 4 hours ago, brian! said: that should work for older versions which still use custom fields, but later releases which either don't or convert an existing custom field to the new regime, would lose their requirement. Yeah - realised that it might not work now it's changed, cheers for that Brian! 0 Quote Link to comment Share on other sites More sharing options...
cosmin Posted October 26, 2020 Author Share Posted October 26, 2020 @brian! Now (probablyfrom the WHMCS 8 ) if in the last page I choose "Already registered" after I click "Submit order" I get the message with "You did not enter your Tax ID". But the ID Number exist in customer's account. If I click again on "Finish order" works... Any idea? Many thanks! 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted October 26, 2020 Share Posted October 26, 2020 1 hour ago, cosmin said: Any idea? ... what happens if you change the if statement to... ? if (!$taxcode && $country === 'RO' && $vars['custtype'] != "existing") { 0 Quote Link to comment Share on other sites More sharing options...
cosmin Posted October 26, 2020 Author Share Posted October 26, 2020 It happens to work perfectly! 😁 Many many thanks!!! 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.