Verifactu in WooCommerce: how to connect your store with the Verifactu API
Verifacti has no official WooCommerce plugin: your store connects to the Verifactu API with your own plugin that, when an order is completed, sends the invoice as JSON and stores the QR the API returns. No XML to generate, no hash to compute and no digital certificate: Verifacti sends the invoicing record to the AEAT as a colaborador social. In Álava, Bizkaia and Gipuzkoa, the same pattern works with the TicketBAI API.
Which APIs you need for WooCommerce
Your connector uses two pieces: the submission API that matches the NIF (Verifactu API in common territory; TicketBAI API in Álava, Bizkaia and Gipuzkoa) and the NIF management API, integrated once to register the NIF, manage the representation form and receive webhooks. Each NIF uses one API or the other depending on where it is taxed.
How to connect WooCommerce with the API
Flow: completed order in WooCommerce (woocommerce_order_status_completed hook) → your plugin → Verifactu API or TicketBAI API → AEAT or foral treasury.
- Register the NIF with the NIF management API and sign the representation form. Each NIF has its own API key.
- Create your own plugin (one file in
wp-content/plugins) and define theVERIFACTI_API_KEYconstant inwp-config.php. - Hook
woocommerce_order_status_completedand callPOST /verifactu/createwithwp_remote_post. - Store
uuid,qrandhuellaas order metadata and add the QR to the PDF invoice.
WooCommerce has no NIF field: the code reads _billing_nif, the one Spanish invoice plugins usually add. Change it to yours. If you'd rather invoice on payment than on completion, hook woocommerce_payment_complete; the rest of the code stays the same.
Do you build software and want to offer Verifactu to your customers? See invoicing software.
Example: from the completed order to the record
A single-file plugin. It goes through the order lines, shipping and fees, takes the VAT rate from each WooCommerce tax rate and groups by rate. It gives the invoice its own sequential number (series WEB-), once per order. If the API does not answer, it retries after 5 minutes with Action Scheduler; if it answers with an error, it notes it on the order.
<?php
/**
* Plugin Name: Verifactu con Verifacti
* Envía cada pedido completado de WooCommerce a la API Verifactu y guarda el QR en el pedido.
* Requiere la constante VERIFACTI_API_KEY en wp-config.php.
*/
// Numeración propia: la factura necesita una serie correlativa y sin huecos, y los números de
// pedido de WooCommerce pueden tenerlos. Cada pedido recibe un número una sola vez.
function verifacti_numero(WC_Order $order): string
{
global $wpdb;
$numero = $order->get_meta('_verifactu_numero');
if ($numero) {
return $numero;
}
add_option('verifacti_ultimo_numero', 0);
$wpdb->query("UPDATE {$wpdb->options} SET option_value = LAST_INSERT_ID(option_value + 1) WHERE option_name = 'verifacti_ultimo_numero'");
$numero = (string) $wpdb->get_var('SELECT LAST_INSERT_ID()');
$order->update_meta_data('_verifactu_numero', $numero);
$order->save();
return $numero;
}
function verifacti_factura(WC_Order $order): array
{
$porTipo = [];
foreach ($order->get_items(['line_item', 'shipping', 'fee']) as $item) {
$tipo = '0'; // línea sin IVA: revisa si es exenta (operacion_exenta) o no sujeta (calificacion_operacion)
foreach ($item->get_taxes()['total'] as $rate_id => $importe) {
if ($importe !== '') {
$tipo = (string) (float) WC_Tax::get_rate_percent_value($rate_id);
}
}
$porTipo[$tipo]['base'] = ($porTipo[$tipo]['base'] ?? 0) + (float) $item->get_total();
$porTipo[$tipo]['cuota'] = ($porTipo[$tipo]['cuota'] ?? 0) + (float) $item->get_total_tax();
}
$nif = $order->get_meta('_billing_nif'); // el campo que añada tu plugin de NIF
$factura = [
'serie' => 'WEB-',
'numero' => verifacti_numero($order),
'fecha_expedicion' => wp_date('d-m-Y'),
'tipo_factura' => $nif ? 'F1' : 'F2',
'descripcion' => 'Pedido ' . $order->get_order_number(),
'lineas' => [],
'importe_total' => number_format((float) $order->get_total(), 2, '.', ''),
];
if ($nif) {
$factura['nif'] = $nif;
$factura['nombre'] = $order->get_billing_company() ?: $order->get_formatted_billing_full_name();
}
foreach ($porTipo as $tipo => $l) {
$factura['lineas'][] = [
'base_imponible' => number_format($l['base'], 2, '.', ''),
'tipo_impositivo' => $tipo,
'cuota_repercutida' => number_format($l['cuota'], 2, '.', ''),
];
}
return $factura;
}
function verifacti_enviar($order_id)
{
$order = wc_get_order($order_id);
if ($order->get_meta('_verifactu_uuid')) {
return;
}
$cuerpo = wp_json_encode(verifacti_factura($order));
$respuesta = wp_remote_post('https://api.verifacti.com/verifactu/create', [
'timeout' => 30,
'headers' => [
'Authorization' => 'Bearer ' . VERIFACTI_API_KEY,
'Content-Type' => 'application/json',
'Idempotency-Key' => 'woo-' . $order->get_id() . '-' . substr(hash('sha256', $cuerpo), 0, 12),
],
'body' => $cuerpo,
]);
$status = is_wp_error($respuesta) ? 0 : wp_remote_retrieve_response_code($respuesta);
if ($status === 0 || $status >= 500) {
$order->add_order_note('Verifactu: sin respuesta, se reintenta en 5 minutos.');
as_schedule_single_action(time() + 300, 'verifacti_reintentar', [$order_id]);
return;
}
$registro = json_decode(wp_remote_retrieve_body($respuesta), true);
if ($status !== 200) {
$order->add_order_note('Verifactu: ' . ($registro['codigo'] ?? '') . ' ' . ($registro['error'] ?? ''));
return;
}
$order->update_meta_data('_verifactu_uuid', $registro['uuid']);
$order->update_meta_data('_verifactu_qr', $registro['qr']);
$order->update_meta_data('_verifactu_huella', $registro['huella']);
$order->save();
}
add_action('woocommerce_order_status_completed', 'verifacti_enviar');
add_action('verifacti_reintentar', 'verifacti_enviar');The code groups the lines by VAT rate and uses F1 if the customer has a NIF and F2 otherwise. It sends the Idempotency-Key header with the order identifier plus a digest of the body: an identical retry never duplicates the invoice and, if you fix the data after an error, the key changes. The response carries the uuid, the state (Pendiente: the submission to the AEAT is queued), the verification URL, the QR in Base64 and the hash: store them with the invoice.
More code in the Verifactu tutorial in PHP. For TicketBAI, the call goes to POST /ticketbai/create with the foral NIF's API key: the fields, in the TicketBAI API documentation.
Special cases in WooCommerce
| Case | What to do | Read more |
|---|---|---|
| Numbering | The code gives each order its own sequential number (series WEB-), once: order numbers can have gaps | Verifactu requirements |
| Customer without a NIF | Simplified invoice (F2), without nif or nombre. The API rejects an F2 above €3,000 (vf-verifactu-f2_limite_3000) | Simplified invoice |
| Return or refund | Corrective invoice: R5 if the original was simplified; R1–R4 if it was a full invoice | Corrective invoices |
| Customer asks for a full invoice later | Exchange invoice (F3) replacing the simplified one | Exchange invoice |
| Canary Islands, Ceuta and Melilla | IGIC or IPSI in the lines (impuesto field), not VAT | IGIC · IPSI |
| Products without VAT | Check whether they are exempt (operacion_exenta) or not subject (calificacion_operacion): they are not sent at rate 0 | Exempt invoice |
| Cancellation | Only for invoices that should never have been issued: POST /verifactu/cancel | Cancellation |
| Sale to another EU country | It depends on whether the customer is a business and on the distance-selling threshold | Intra-EU examples |
| Several companies or shops | One NIF per company, each with its own API key | NIF management API |
Dates
The first row only applies if you build the connector to sell it: then you sell invoicing software. For those who invoice, the Verifactu dates are published in the BOE and the postponement to October 2028 is announced with no rule published. In Álava, Bizkaia and Gipuzkoa, TicketBAI is in force.
| Who | Date | Status | Rule |
|---|---|---|---|
| Producers and resellers of invoicing software RDL 15/2025 did not change this date. | Since 29 Jul 2025 | In force | RD 1007/2023 · Orden HAC/1177/2024 |
| Corporate Income Tax payers | 1 Jan 2027 | Published in the BOE, future date | RDL 15/2025 |
| Everyone else, including the self-employed | 1 Jul 2027 | Published in the BOE, future date | RDL 15/2025 |
| Postponement of the pending obligations The note does not specify the scope for businesses invoicing over €8M. | Oct 2028 | Announced, no rule published | Nota de Hacienda, 5 oct 2026 |
| TicketBAI in Álava: foral taxpayers Phased from 1 April 2022; all other taxpayers since 1 December 2022. | Since 1 Dec 2022 | In force | NF 13/2021 y DF 48/2021 · FAQ 1.9 · calendario |
| Batuz in Bizkaia (TicketBAI and LROE): all taxpayers Companies that are not SMEs since 1 January 2024; everyone else in windows on 1 July 2024, 1 January 2025, 1 July 2025 and 1 January 2026. | Since 1 Jan 2026 | In force | NF 8/2023 · Batuz |
| TicketBAI in Gipuzkoa: foral taxpayers Phased by activity from 1 July 2022. | Since 1 Jun 2023 | In force | NF 3/2020 · DF 32/2020 |
This is not advice: each taxpayer determines what applies to them with their adviser.
More detail in Verifactu dates and TicketBAI.
Pricing
Public tariff of the Verifactu API and the TicketBAI API: you pay per NIF active in production, VAT excluded. Custom per-NIF pricing is available for volume.
From
€14.99
per month for the first NIF active in production, VAT excluded
See all pricing- The price per NIF goes down with every tier.
- Free test environment and test NIF.
- Annual plan with a 10% discount, no setup fees.
- Up to 3,000 invoicing records per month per NIF.
- Startup plan for companies under 12 months old, with under €100,000 in revenue and under €200,000 in funding.
- Same price with the Verifactu API and the TicketBAI API: each NIF uses one or the other depending on where it is taxed.
- Online signing of the representation form: €2.90 + VAT per signature.
Developer resources
For your AI: llms.txt and the OpenAPI specification.
Questions about Verifactu and WooCommerce
More questions about VerifactuIs there a plugin from Verifacti for WooCommerce?
Does WooCommerce comply with Verifactu on its own?
Does it work for TicketBAI too?
/ticketbai/create), the invoice fields and the API key change.Do I need a digital certificate?
How much does it cost?
Other integrations
Connect WooCommerce in the test environment
Create your free account and try the API with a test NIF before going to production.