Docs/Integrations/n8n/Templates/WooCommerce Orders as XRechnung

WooCommerce Orders as XRechnung

Automatically generate compliant XRechnung e-invoices for completed WooCommerce orders and email them to customers.

WooCommerceInvoice-api.xhubGmail10 min setup

How This Workflow Works

WooCommerce Orders as XRechnung — Workflow Diagram
  1. 1

    Triggers on every completed WooCommerce order

  2. 2

    Maps order data (items, billing, totals) to the e-invoice format

  3. 3

    Generates a compliant XRechnung (EN 16931) via the API

  4. 4

    Emails the XRechnung as XML attachment to the customer

  5. 5

    Updates the WooCommerce order with a delivery confirmation note

Why This Matters

Starting 2025, German businesses must be able to receive and process e-invoices. B2B customers increasingly expect XRechnung or ZUGFeRD. Manual invoice creation doesn't scale with order volume.

Google Sheets Structure

WooCommerceInvoice
order.idInvoice Number (WOO-{id})
billing.first_name + last_nameBuyer Name
billing.companyBuyer Name (fallback)
billing.address_1 + city + postcodeBuyer Address
line_items[].name + quantity + priceInvoice Line Items
total + total_taxInvoice Total + VAT
meta_data[vat_id]Buyer VAT ID (optional)

Setup Steps

  1. 1

    Install the n8n-nodes-invoice-api-xhub community node

  2. 2

    Create an API key at invoice-api.xhub.io

  3. 3

    Create WooCommerce API key: WooCommerce > Settings > Advanced > REST API > Add Key (Read/Write)

  4. 4

    Set up Gmail OAuth2 credential in n8n

  5. 5

    Configure invoice-api.xhub credential with API key

  6. 6

    Update seller info in the 'Map Order to Invoice' Code node

  7. 7

    Activate the workflow

Preview (truncated)

json
1{
2 "name": "WooCommerce Order to XRechnung Email",
3 "nodes": [
4 {
5 "id": "woo-trigger",
6 "name": "WooCommerce Trigger",
7 "type": "n8n-nodes-base.wooCommerceTrigger",
8 "typeVersion": 1,
9 "position": [400, 600],
10 "parameters": {
11 "event": "order.created"
12 },
13 "credentials": {
14 "wooCommerceApi": {
15 "id": "",
16 "name": "WooCommerce account"
17 }
18 }
19 },
20 {
21 "id": "map-order-to-invoice",
22 "name": "Map Order to Invoice",
23 "type": "n8n-nodes-base.code",
24 "typeVersion": 2,
25 "position": [640, 600],
26 "parameters": {
27 "mode": "runOnceForEachItem",
28 "jsCode": "const order = $json;\n\n// Map WooCommerce line items\nconst lineItems = (order.line_items || []).map(item => ({\n description: item.name || '',\n quantity: item.quantity || 1,\n unitPrice: parseFloat(item.price || 0),\n vatRate: 19, // Adjust based on your tax setup\n unit: 'EA'\n}));\n\nconst subtotal = parseFloat(order.total || 0) - parseFloat(order.total_tax || 0);\nconst totalVat = parseFloat(order.total_tax || 0);\nconst total = parseFloat(order.total || 0);\n\nconst invoice = {\n invoiceNumber: `WOO-${order.id || order.number || Date.now()}`,\n invoiceDate: new Date().toISOString().split('T')[0],\n dueDate: '',\n currency: order.currency || 'EUR',\n seller: {\n name: 'Your Company Name',\n vatId: 'DE000000000',\n email: 'invoices@yourcompany.de',\n address: {\n street: 'Your Street 1',\n city: 'Your City',\n postalCode: '10115',\n country: 'DE'\n }\n },\n buyer: {\n name: `${order.billing?.first_name || ''} ${order.billing?.last_name || ''}`.trim() || order.billing?.company || '',\n vatId: order.meta_data?.find(m => m.key === 'vat_id')?.value || '',\n email: order.billing?.email || '',\n address: {\n street: `${order.billing?.address_1 || ''} ${order.billing?.address_2 || ''}`.trim(),\n city: order.billing?.city || '',\n postalCode: order.billing?.postcode || '',\n country: order.billing?.country || 'DE'\n }\n },\n lineItems,\n subtotal,\n totalVat,\n total\n};\n\nreturn {\n json: {\n orderId: order.id || order.number,\n buyerEmail: order.billing?.email || '',\n invoiceNumber: invoice.invoiceNumber,\n invoiceData: JSON.stringify(invoice)\n }\n};"
29 }
30 },
31 // ... (truncated)

Use Cases

German E-Commerce

Comply with the E-Invoice Mandate 2025

B2B Shops

Automatically provide XRechnung to business customers

Public Sector Sales

Generate B2G compliant invoices

EU Cross-Border

Switch to UBL or Factur-X for other EU countries

Get Started Now

Import the workflow into your n8n instance and get started in minutes.