Frameworks
WooCommerce — Intégration Scell.io
Facture Factur-X automatique sur completion de commande
Le SDK PHP `scell/sdk` v3.5.0 s'utilise dans un plugin WooCommerce pour générer une facture Factur-X conforme à chaque commande payée. Hook `woocommerce_order_status_completed` pour déclencher la création, mapping `WC_Order_Item_Product` → lignes Scell. Auto-détection B2C (pas de SIRET buyer) et application automatique de BR-CO-26.
À retenir
- Hook `woocommerce_order_status_completed`
- Auto-détection B2C via `$order->get_meta('_billing_company')`
- Mapping `WC_Order_Item_Product` → `addLine()`
- PDF Factur-X attaché à l'email de confirmation
- Compatible WooCommerce 8.0+ et HPOS
Exemple de code
use Scell\Sdk\Client;
add_action('woocommerce_order_status_completed', function ($order_id) {
$order = wc_get_order($order_id);
$client = new Client(get_option('scell_api_key'));
$builder = $client->invoices()->builder()->facturX();
foreach ($order->get_items() as $item) {
$builder->addLine($item->get_name(), $item->get_quantity(), $item->get_total(), 20.0);
}
$invoice = $builder->buyerIndividual($order->get_formatted_billing_full_name())->create();
$order->update_meta_data('_scell_invoice_id', $invoice->id);
$order->save();
});