Skip to content

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.

The NIP module checks the number at three levels:

  1. Format validation: the number must have 10 digits; spaces and hyphens are ignored
  2. Checksum validation: NIP check digit verification algorithm
  3. GUS REGON lookup: a search in the Central Statistical Office register with automatic company data retrieval

Enable NIP - Verification and Autocomplete under Polski > Modules and expand its 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.

The NIP validation algorithm is based on a weight system. The check digit (last, tenth digit) is calculated based on the nine preceding digits.

Weights for consecutive NIP digits: 6, 5, 7, 2, 3, 4, 5, 6, 7

NIP: 5260250274
Sum = 5*6 + 2*5 + 6*7 + 0*2 + 2*3 + 5*4 + 0*5 + 2*6 + 7*7 = 169
Remainder = 169 mod 11 = 4
If remainder == last NIP digit -> NIP is valid

The plugin checks the number in the browser (JavaScript, before it calls GUS) and on the server (PHP). Server-side validation is always active.

The plugin accepts NIP in these formats:

  • 1234567890: digits only
  • 123-456-78-90: with hyphens
  • 123 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.

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.

  1. Go to: https://api.stat.gov.pl/Home/BirIndex
  2. Register and log in
  3. Submit a request for REGON API access
  4. The key will be sent to the provided email address (wait time: 1-3 business days)
  1. Go to Polski > Modules and expand the NIP module
  2. Select GUS API environment: Testing or Production
  3. Paste the API key (for the production environment)
  4. Save settings

In test mode, the plugin uses the public GUS test key. The test database contains fictitious data. Use it only during development and testing.

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.

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.

  • 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."

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_nip and _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
$order = wc_get_order($order_id);
$nip = $order->get_meta('_billing_nip');
use Polski\Util\NipValidator;
NipValidator::isValid('526-025-02-74'); // true

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

  1. Check that the API key is correct and active, and that the environment matches the key
  2. Verify that the server can open an HTTPS connection to wyszukiwarkaregon.stat.gov.pl
  3. 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.

  1. Check that the NIP module is enabled
  2. Clear cache (caching plugins may cache the checkout form)

Company data does not auto-complete

Section titled "Company data does not auto-complete"
  1. Check the browser console for errors from the admin-ajax.php request with the polski_nip_lookup action
  2. Check whether the lookup limit was reached for your IP
  3. 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.

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.

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.

This page is for informational purposes only and does not constitute legal advice. Consult a lawyer before implementation. Polski for WooCommerce is open source software (GPLv2) provided without warranty.