What's possible?
| Where | Possible? | How |
|---|---|---|
| Cart | Yes, all plans | Cart attributes + a little theme JavaScript |
| Customer sign-up | Yes, all plans | Extra field in the registration form |
| Checkout | Limited | Checkout 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.
{%- 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.
// 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.
{%- 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]">
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.