Italian Tax Field Validation in WHMCS (SDI, PEC, Tax Code)
If you use WHMCS for the Italian market, you already know that managing tax fields can quickly become a problem.
SDI, PEC, Tax Code, and VAT number cannot be conditionally required in a clean way using only standard custom fields. Additionally, during checkout, when a registered user logs in directly on the payment page, WHMCS dynamically hides the registration section, often causing the cart to freeze.
We have therefore developed a free hook that permanently solves this issue without modifying templates and without compromising the checkout flow.
The Technical Problem
WHMCS does not allow custom fields to be made truly conditional required fields. If a field is set as required but is dynamically hidden (for example when a customer logs in during checkout), the browser blocks the form submission.
Result:
- Checkout does not proceed
- No clear message for the user
- Cart appears “frozen”
- User experience compromised
The issue is not WHMCS itself, but the combination of HTML5 validation and hidden fields.
What This Hook Does
- Makes SDI, PEC, and Tax Code mandatory only for the Italian market
- Keeps the VAT number field always visible
- Automatically hides tax fields for non-Italian users
- Detects when the registration section is hidden during checkout
- Properly disables validation when necessary
- Requires no template modifications
- Compatible with WHMCS 8.13+
How It Works
The system intercepts the language parameter in the URL and determines whether the user is in the Italian context.
During checkout, it checks the status of the #containerNewUserSignup container. If WHMCS hides it (login during checkout scenario), the hook dynamically removes the required attribute from the tax fields to prevent the browser from blocking submission.
Everything is handled via ClientAreaHeadOutput, without structural changes to the theme.
Installation
1. Create the Custom Fields in WHMCS
Go to Setup → Custom Client Fields and create the following fields:
SDI
PEC
Tax Code (Codice Fiscale)
VAT / VAT Number
Important: you can set the field order as you prefer, but do NOT mark them as Required in WHMCS. Validation is handled directly by the hook.
2. Note the Field IDs
After creating the custom fields, take note of their IDs. You can find them in the URL when editing the field or directly in the database.
3. Upload the Hook
Upload the file to the following directory:
/includes/hooks/4. Set the Field IDs in the File
Open the hook file and insert the IDs as follows:
$SDI_FIELD_ID = 1;$PEC_FIELD_ID = 2;$CF_FIELD_ID = 3;$VAT_FIELD_ID = 4;No template modifications are required. The hook will automatically run during registration and checkout.
Why We Made It Free
This hook was created to solve a real issue encountered in multiple Italian WHMCS projects. We decided to make it available for free because we believe a solid technical foundation improves the entire ecosystem.
If you use WHMCS for the Italian market, this small intervention can save you many hours of debugging.
Need WHMCS Customizations?
If you are developing advanced solutions on WHMCS or want to implement custom features, contact us.
We develop custom modules, hooks, and integrations.