Jump to content

How to make required tax id field?


Recommended Posts

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";

q1HvSVx.png

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 by brian!
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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! 

Link to comment
Share on other sites

  • 1 year later...

@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!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated