CVR lookup in Shopify

Shopify doesn't let you freely add fields to checkout, so the CVR lookup has to live somewhere else. The simplest option is a CVR field in the cart that looks up the company and sends the data along with the order as cart attributes.

What's possible?

WherePossible?How
CartYes, all plansCart attributes + a little theme JavaScript
Customer sign-upYes, all plansExtra field in the registration form
CheckoutLimitedCheckout UI extensions, mainly on Shopify Plus

1. CVR field in the cart

Add the fields to your cart section. The form="cart" attribute ties them to the cart form (in the Dawn theme its id is cart). Anything named attributes[...] is saved with the order and shown in admin under Additional details.

liquid
{%- comment -%} In the cart section, e.g. sections/main-cart-footer.liquid {%- endcomment -%}
<div class="cart-attribute">
  <label for="cvr-number">CVR number</label>
  <input id="cvr-number" type="text" inputmode="numeric" maxlength="8"
         name="attributes[CVR]" form="cart"
         value="{{ cart.attributes.CVR }}">
</div>
<div class="cart-attribute">
  <label for="cvr-company">Company name</label>
  <input id="cvr-company" type="text"
         name="attributes[Company]" form="cart"
         value="{{ cart.attributes.Company }}">
</div>
<p id="cvr-status" aria-live="polite"></p>

2. Look up the company with JavaScript

The API allows requests from any origin (CORS), so the script can call it straight from your storefront without an app or a proxy.

javascript
// assets/cvr-lookup.js, loaded on the cart page
const cvrInput = document.getElementById('cvr-number');
const companyInput = document.getElementById('cvr-company');
const status = document.getElementById('cvr-status');

cvrInput?.addEventListener('input', async () => {
  const cvr = cvrInput.value.replace(/\D/g, '');
  status.textContent = '';
  if (cvr.length !== 8) return;

  try {
    const res = await fetch(`https://apicvr.dk/api/v1/${cvr}`);
    if (!res.ok) {
      status.textContent = 'CVR not found';
      return;
    }
    const company = await res.json();
    companyInput.value = company.name;
    status.textContent = `${company.name}, ${company.address}, ${company.zipcode} ${company.city}`;
  } catch (err) {
    // Leave the fields for the customer to fill in.
  }
});

3. CVR at customer sign-up

If your B2B customers create accounts, you can ask for the CVR number at sign-up too. Fields named customer[note][...] are saved to the customer's note.

liquid
{%- comment -%} Inside the customer registration form (customers/register) {%- endcomment -%}
<label for="RegisterForm-CVR">CVR number</label>
<input id="RegisterForm-CVR" type="text" inputmode="numeric" maxlength="8"
       name="customer[note][CVR]">
Checkout itself can only be extended with Checkout UI extensions, and for the information, shipping and payment steps that generally requires Shopify Plus. Extensions also need network access enabled to call an external API.

Respect marketing protection

If you use customers' company data for marketing, check the protected field in the API response. See marketing protection.

Frequently asked questions

Do I need to install an app?

No. The cart fields and the script live in your theme, and the API needs no key.

Where do I find the CVR number on the order?

Cart attributes appear on the order in Shopify admin under Additional details, and in order webhooks and the API as note_attributes.

Can I add the CVR field to checkout itself?

Only with Checkout UI extensions, which for the information and payment steps generally require Shopify Plus.