NIP at checkout
Business customers need a NIP field at checkout to receive a VAT invoice. Polski for WooCommerce adds a NIP field with checksum validation and GUS REGON verification. Company data fills in automatically.
Features
Section titled “Features”The NIP module verifies the number at three levels:
- Format validation - checking that the number consists of 10 digits
- Checksum validation - NIP check digit verification algorithm
- GUS REGON verification - checking in the Central Statistical Office database with automatic company data retrieval
Configuration
Section titled “Configuration”Go to WooCommerce > Settings > Polski > Checkout and configure the “NIP” section.
Basic settings
Section titled “Basic settings”| Setting | Default value | Description |
|---|---|---|
| Enable NIP field | Yes | Adds NIP field to the checkout page |
| Field required | No | Whether NIP is mandatory |
| Field position | After company field | Where to display the NIP field |
| Checksum validation | Yes | Checks NIP number correctness |
| GUS REGON verification | No | Verifies NIP in the GUS database |
| Automatic completion | Yes | Retrieves company data from GUS |
Conditional display
Section titled “Conditional display”The NIP field can be displayed:
- Always - visible to all customers
- After checking “I want an invoice” - appears after checking
- After entering a company name - appears when the “Company” field is filled
The recommended option is displaying after checking “I want an invoice” - this is the clearest for the customer.
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: 1234567890Sum = 1*6 + 2*5 + 3*7 + 4*2 + 5*3 + 6*4 + 7*5 + 8*6 + 9*7 = 214Remainder = 214 mod 11If remainder == last NIP digit -> NIP is validThe plugin validates both client-side (JavaScript) and server-side (PHP). Server-side validation is always active.
Input format handling
Section titled “Input format handling”The plugin accepts NIP in various formats:
1234567890- digits only123-456-78-90- with hyphens123 456 78 90- with spacesPL1234567890- with country prefix
All formats are normalized to 10 digits before validation.
GUS REGON verification
Section titled “GUS REGON verification”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/UslugaBIRzewnwordbir.svc | abcde12345abcde12345 (public test key) | Development and testing |
| Production | https://wyszukiwarkaregon.stat.gov.pl/wsBIR/UslugaBIRzewnetrzny.svc | Your own key from GUS | Live store |
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 WooCommerce > Settings > Polski > Checkout > NIP
- Enable GUS REGON verification
- Select environment: Test 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.
Automatic company data retrieval
Section titled “Automatic company data retrieval”After verifying NIP in GUS REGON, the plugin automatically completes form fields:
| WooCommerce field | GUS data |
|---|---|
| Company | Company name |
| Address 1 | Street and number |
| City | City |
| Postal code | Postal code |
| State/Province | Province |
The customer sees the completed data and can correct them before placing the order.
Auto-completion behavior
Section titled “Auto-completion behavior”- Fields are completed only if they are empty or contain previously retrieved GUS data
- If the customer manually changed the data, the plugin does not overwrite changes
- The customer is informed with a message about the data retrieval
NIP storage
Section titled “NIP storage”The NIP number is saved as order metadata:
- key:
_billing_nip - visible in the admin panel order view
- available in email templates
- exportable in reports
Displaying NIP in the order
Section titled “Displaying NIP in the order”NIP is automatically displayed:
- in order details (admin panel)
- in the order confirmation email
- on the “My Account > Orders” page
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”function validate_nip(string $nip): bool { $nip = preg_replace('/[^0-9]/', '', $nip);
if (strlen($nip) !== 10) { return false; }
$weights = [6, 5, 7, 2, 3, 4, 5, 6, 7]; $sum = 0;
for ($i = 0; $i < 9; $i++) { $sum += (int) $nip[$i] * $weights[$i]; }
return ($sum % 11) === (int) $nip[9];}Validation hook
Section titled “Validation hook”add_filter('polski/checkout/validate_nip', function (bool $is_valid, string $nip): bool { // Additional validation logic // e.g. checking against a blocked NIP list $blocked_nips = ['0000000000'];
if (in_array($nip, $blocked_nips, true)) { return false; }
return $is_valid;}, 10, 2);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
- Verify that the server can establish an HTTPS connection to api.stat.gov.pl
- The GUS API can be unavailable - the plugin handles timeouts and displays an appropriate message
- Make sure the PHP SOAP extension is installed on the server
NIP field does not display
Section titled “NIP field does not display”- Check that the NIP module is enabled
- Verify the conditional display setting
- 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 AJAX errors
- Verify that the plugin REST API endpoint is accessible
- Make sure the NIP is correct and the company exists in the GUS database