Validate a Swiss UID number in WooCommerce
Anyone selling to businesses in Switzerland asks for the business identification number, the UID, in the checkout or in the quote form. Whether the number entered is correct and whether the company still exists can be checked in three steps: format, check digit and entry in the federal UID register. This guide shows all three, by hand and in a WooCommerce shop.
What a Swiss UID is
The UID is the single number under which a company is known to Swiss authorities. It is assigned by the Federal Statistical Office (FSO) and listed in the UID register. When an authority reports a new company, it receives its UID there. The register also knows companies that are not in the commercial register, such as many sole proprietorships and associations.
The number consists of the prefix "CHE" and nine digits, written CHE-123.456.789. The last digit is a check digit. If a company is registered for VAT, its invoices show the same number followed by "MWST", in French "TVA", in Italian "IVA".
Step 1: check the format
Customers type the UID in many ways. A check should accept all of them that mean the same number and then store it in one form:
- with dots and hyphen: CHE-353.272.857
- without separators: CHE353272857
- with spaces: CHE 353 272 857
- with the VAT suffix: CHE-353.272.857 MWST
So the prefix CHE is allowed, followed by exactly nine digits, with at most dots, hyphens or spaces between them, and optionally MWST, TVA or IVA at the end. It is always stored as CHE-353.272.857, so the same company does not end up in the system twice under different spellings.
Step 2: calculate the check digit
The ninth digit follows from the first eight, using the modulo 11 method. That way the check catches most typing errors without asking the register:
- Multiply the first eight digits by the weights 5, 4, 3, 2, 7, 6, 5, 4 and add them up.
- Divide the sum by 11 and take the remainder.
- The check digit is 11 minus this remainder. If that gives 11, the check digit is 0. If it gives 10, the number is not a valid UID.
An example with the digits 1 2 3 4 5 6 7 8: 1·5 + 2·4 + 3·3 + 4·2 + 5·7 + 6·6 + 7·5 + 8·4 gives 168. 168 divided by 11 leaves a remainder of 3, so the check digit is 11 − 3 = 8. The number CHE-123.456.788 therefore has a valid format. CHE-123.456.789, often used as a sample, does not.
A correct check digit does not yet mean the company exists. Only the register can tell.
Step 3: look it up in the UID register
By hand, this works on uid.admin.ch: enter the UID or company name, and the register shows name, legal form, address, status and the entry in the VAT register.
For a shop there is the FSO's UID web service. Its "PublicServices" can be used publicly without
a login, in a limited form, and free of charge. The web service speaks SOAP, and the data follows
the eCH-0108 standard. Looking up a single number is called GetByUID:
POST https://www.uid-wse.admin.ch/V5.0/PublicServices.svc
SOAPAction: "http://www.uid.admin.ch/xmlns/uid-wse/IPublicServices/GetByUID"
<uid:GetByUID>
<uid:uid>
<ech:uidOrganisationIdCategorie>CHE</ech:uidOrganisationIdCategorie>
<ech:uidOrganisationId>353272857</ech:uidOrganisationId>
</uid:uid>
</uid:GetByUID>
The response contains name, legal form, address and status. The status values 3 (definitive) and 4 (being changed) count as active; 5 and 6 mean deleted, 7 cancelled. If the organisation is missing from the response, the number is not in the register.
UID register or Zefix?
Zefix is the central business name index of the commercial register. It only lists companies with a commercial register entry, but with purpose, capital and the publications in the Swiss Official Gazette of Commerce. For the question "Does this UID exist, and is the company active?" the UID register is the better source: it knows more companies and can be queried without credentials. The Zefix interface needs an account. How it works is explained in the guide on the Zefix API.
What goes wrong in a shop
Without a check, the shop collects numbers nobody can use later:
- typos and swapped digits that only show up at invoicing or in the dunning run
- the same company several times, because the UID was stored once with dots and once without
- invoice orders from companies deleted from the register long ago
- plugins for the EU VAT number that validate through the EU's VIES system: VIES does not know the Swiss UID, so the check goes nowhere
- a register outage that blocks the whole checkout although the number is correct
A good check therefore validates format and check digit immediately in the shop, asks the register only after that, caches the answer for a while and lets a number with a correct check digit through when the register does not respond.
Guide: set up the UID check in the WooCommerce checkout
That is exactly what my free plugin "Strainovic UID Check Schweiz" from the WordPress plugin directory does:
- In the WordPress admin, under "Plugins → Add New", search for "Strainovic UID Check Schweiz" and install it.
- Activate it. The "UID" field appears in the WooCommerce checkout on its own, in the contact section of the Checkout block, after the company name in the classic checkout. It is optional and validated as soon as it is filled in.
- For Contact Form 7, add a text field named
uidto the form, for example[text uid], or[text* uid]for a required field. - Test it: with CHE-123.456.789 the form reports an invalid number, with a deleted company a rejection, with an active company the order goes through.
The plugin needs no account and no key. Only the nine digits go to the register, from the shop's server, never the customer's name or address. Each answer is cached for one day, so the same number is looked up at most once a day.
Check result in bexio
If you manage your customers in bexio, you usually need the result there. The UID Check for bexio version queries the register on every order, stores the result with a timestamp on the order and creates the contact and a check note in bexio.