NIP at checkout
The NIP module in Polski for WooCommerce adds a NIP (Polish tax ID) field to the WooCommerce checkout and the My Account billing address. It checks the NIP checksum and, once a valid number is typed, fetches the company name and address from the GUS REGON register to fill the billing fields. The module is off by default and works on classic and block checkout.
Features
Section titled "Features"The NIP module checks the number at three levels:
- Format validation: the number must have 10 digits; spaces and hyphens are ignored
- Checksum validation: NIP check digit verification algorithm
- GUS REGON lookup: a search in the Central Statistical Office register with automatic company data retrieval
Configuration
Section titled "Configuration"Enable NIP - Verification and Autocomplete under Polski > Modules and expand its settings.
Basic settings
Section titled "Basic settings"The module has these settings, stored in the polski_nip option (the "Buying as" switch in polski_b2b).
| Setting | Default value | Description |
|---|---|---|
| NIP required on checkout | No | Makes the NIP field mandatory. Left off, the field is optional. |
| NIP field label | empty | Your own label for the field on the classic and block checkout. Empty keeps "NIP", or "NIP or EU VAT ID" with the VIES module on. |
| Ask "Buying as: Personal / Company" on the block checkout | No | A required choice under the e-mail on the block checkout. Company shows a company name field and the NIP, Personal hides them. See B2B checkout fields. |
| GUS API environment | Testing | Testing uses the GUS sandbox key, Production uses your own. |
| GUS API Key (production) | empty | Requested from the stat.gov.pl website. |
Checksum validation always runs and is not a setting. Company data is retrieved from GUS whenever a valid NIP is entered and a working key is configured.
Where the field appears, and where the company name comes from
Section titled "Where the field appears, and where the company name comes from"Turning the module on adds one field, NIP, and nothing else. On the classic checkout it is present for every customer, optional unless you make it required. On the block checkout the "Buying as" choice above can hide it for Personal buyers; then "NIP required on checkout" applies to Company only.
| Place | Field |
|---|---|
| Classic checkout | billing_nip in the billing section, after the company name (priority 31) |
| Block checkout | polski/nip in the contact section, so it is entered once, not per address |
| My Account > Addresses > Billing | billing_nip, validated on save like at checkout |
| Order screen (admin) | Printed as "NIP" below the billing address |
The company name is WooCommerce's own billing field, not ours. Show or hide it under WooCommerce > Settings > Accounts and Privacy, or in the Checkout block's settings on block checkout, where "Company" can be set to hidden, optional or required. Polski fills it from GUS when it can and otherwise leaves it as WooCommerce stores it.
With the VIES module also on, the field is labelled "NIP or EU VAT ID" and accepts an EU VAT number with its country code as well.
Checksum validation
Section titled "Checksum validation"The NIP validation algorithm is based on a weight system. The check digit (last, tenth digit) is calculated based on the nine preceding digits.
Algorithm
Section titled "Algorithm"Weights for consecutive NIP digits: 6, 5, 7, 2, 3, 4, 5, 6, 7
NIP: 5260250274Sum = 5*6 + 2*5 + 6*7 + 0*2 + 2*3 + 5*4 + 0*5 + 2*6 + 7*7 = 169Remainder = 169 mod 11 = 4If remainder == last NIP digit -> NIP is validThe plugin checks the number in the browser (JavaScript, before it calls GUS) and on the server (PHP). Server-side validation is always active.
Input format handling
Section titled "Input format handling"The plugin accepts NIP in these formats:
1234567890: digits only123-456-78-90: with hyphens123 456 78 90: with spaces
Spaces and hyphens are removed before validation. A PL prefix (PL1234567890) is accepted only when the VIES module is on.
GUS REGON lookup
Section titled "GUS REGON lookup"API configuration
Section titled "API configuration"The GUS REGON API requires an access key. The plugin supports two environments:
| Environment | URL | Key | Use |
|---|---|---|---|
| Test | https://wyszukiwarkaregontest.stat.gov.pl/wsBIR/UslugaBIRzewnPubl.svc |
abcde12345abcde12345 (public test key) |
Development and testing |
| Production | https://wyszukiwarkaregon.stat.gov.pl/wsBIR/UslugaBIRzewnPubl.svc |
Your own key from GUS | Live store |
In Production without a key the plugin skips the lookup, and the customer fills in the details by hand.
Obtaining a production key
Section titled "Obtaining a production key"- Go to: https://api.stat.gov.pl/Home/BirIndex
- Register and log in
- Submit a request for REGON API access
- The key will be sent to the provided email address (wait time: 1-3 business days)
Plugin configuration
Section titled "Plugin configuration"- Go to Polski > Modules and expand the NIP module
- Select GUS API environment: Testing or Production
- Paste the API key (for the production environment)
- Save settings
Test mode
Section titled "Test mode"In test mode, the plugin uses the public GUS test key. The test database contains fictitious data. Use it only during development and testing.
Lookup limit
Section titled "Lookup limit"Every visitor can call the lookup, so the plugin limits it to 10 lookups per hour per IP address. Users with the manage_woocommerce capability are not limited. Past the limit the customer sees "Too many VAT ID (NIP) lookups. Fill the details in by hand or try again in an hour." Both numbers are filterable:
add_filter('polski/nip_lookup/rate_limit_max_attempts', fn () => 20);add_filter('polski/nip_lookup/rate_limit_window_seconds', fn () => HOUR_IN_SECONDS);Returning 0 from either filter turns the limit off.
Automatic company data retrieval
Section titled "Automatic company data retrieval"After a valid NIP is typed, the plugin asks GUS for the company and fills these billing fields:
| WooCommerce field | GUS data |
|---|---|
| Company | Company name |
| Address 1 | Street, building number and unit number |
| Postcode | Postal code |
| City | City |
The customer sees the completed data and can correct them before placing the order.
Auto-completion behavior
Section titled "Auto-completion behavior"- Only fields for which GUS returned a value are written; a missing value never blanks a field
- A field GUS did return is overwritten, even if the customer typed something there earlier
- The same NIP is not looked up twice in a row
- On the block checkout the data goes into the billing address; with "Use same address for billing" ticked, the plugin unticks it first so the customer sees the filled billing form
- When GUS has no record, the customer sees "No data found for that VAT ID (NIP). Check the number or fill the details in by hand."
NIP storage
Section titled "NIP storage"The NIP is saved as order metadata, as bare digits (an EU VAT ID accepted through the VIES module keeps its country prefix):
- keys:
_billing_nipand_polski_billing_nip - shown on the admin order screen below the billing address
- copied to the customer's account, so the next checkout and the My Account form show the same number
Programmatic access
Section titled "Programmatic access"Getting NIP from an order
Section titled "Getting NIP from an order"$order = wc_get_order($order_id);$nip = $order->get_meta('_billing_nip');NIP validation in PHP
Section titled "NIP validation in PHP"use Polski\Util\NipValidator;
NipValidator::isValid('526-025-02-74'); // trueRequirement hook
Section titled "Requirement hook"polski/nip_required decides whether the NIP is mandatory. It receives the "NIP required on checkout" setting and a flag that is true while the block checkout field is being registered, when no cart exists yet.
add_filter('polski/nip_required', function (bool $required, bool $atRegistration): bool { // Example: require a NIP for logged-in customers with the wholesale role if (! $atRegistration && current_user_can('wholesale_customer')) { return true; } return $required;}, 10, 2);When the requirement comes from the cart and the field is empty, checkout stops with "One of the products in your order needs a VAT ID (NIP) on the receipt. Enter it to continue."
Common issues
Section titled "Common issues"GUS verification returns an error
Section titled "GUS verification returns an error"- Check that the API key is correct and active, and that the environment matches the key
- Verify that the server can open an HTTPS connection to wyszukiwarkaregon.stat.gov.pl
- The GUS API can be unavailable: each request waits up to 10 seconds and is retried once on a timeout or a 5xx answer, then the customer can fill the data in by hand
The lookup sends plain HTTP requests, so the PHP SOAP extension is not needed.
NIP field does not display
Section titled "NIP field does not display"- Check that the NIP module is enabled
- Clear cache (caching plugins may cache the checkout form)
Company data does not auto-complete
Section titled "Company data does not auto-complete"- Check the browser console for errors from the
admin-ajax.phprequest with thepolski_nip_lookupaction - Check whether the lookup limit was reached for your IP
- Make sure the NIP is correct and the company exists in the GUS database
Is the NIP field required at checkout?
Section titled "Is the NIP field required at checkout?"Only if you tick "NIP required on checkout". By default it is optional. Code can change the requirement per cart with the polski/nip_required filter.
Do I need my own GUS API key?
Section titled "Do I need my own GUS API key?"For a live shop, yes. The Testing environment uses the public test key and returns fictitious data. Production without a key skips the lookup, while the checksum check still runs.
Where is the NIP saved?
Section titled "Where is the NIP saved?"On the order under _billing_nip and _polski_billing_nip, as 10 digits, and on the customer's account. The KSeF and invoice modules read _billing_nip.