Akce po vytvoření dokumentu
Po úspěšném vytvoření dokumentu ve Fakturoidu je spuštěna akce, která umožňuje reagovat na tuto událost - například odeslat notifikaci, aktualizovat externí systém nebo provést další operace.
Akce po vytvoření dokumentu
Section titled “Akce po vytvoření dokumentu”do_action( 'wpify_woo_fakturoid_document_created', $order, $wc_order, $document_type );Parametry akce
Section titled “Parametry akce”| Parametr | Typ | Popis |
|---|---|---|
$order | OrderModel | Model objednávky s Fakturoid daty |
$wc_order | WC_Order | WooCommerce objednávka |
$document_type | string | Typ dokumentu: proforma, invoice, correction |
Příklady použití
Section titled “Příklady použití”Logování vytvořených dokumentů
Section titled “Logování vytvořených dokumentů”Pro debugování a sledování vytvářených dokumentů.
/** * Log created Fakturoid documents * * @param OrderModel $order Order model * @param WC_Order $wc_order WC order * @param string $document_type Document type * * @return void */function log_fakturoid_document( $order, $wc_order, $document_type ): void { error_log( sprintf( 'Fakturoid %s created for order #%s', $document_type, $wc_order->get_order_number() ) );}add_action( 'wpify_woo_fakturoid_document_created', 'log_fakturoid_document', 10, 3 );Odeslání notifikace po vytvoření faktury
Section titled “Odeslání notifikace po vytvoření faktury”/** * Send notification after invoice creation * * @param OrderModel $order Order model * @param WC_Order $wc_order WC order * @param string $document_type Document type * * @return void */function notify_on_invoice_created( $order, $wc_order, $document_type ): void { // Pouze pro faktury (ne proformy) if ( $document_type !== 'invoice' ) { return; }
// Odeslat email administrátorovi wp_mail( get_option( 'admin_email' ), 'Nová faktura vytvořena', sprintf( 'Pro objednávku #%s byla vytvořena faktura', $wc_order->get_order_number() ) );}add_action( 'wpify_woo_fakturoid_document_created', 'notify_on_invoice_created', 10, 3 );Synchronizace s externím systémem
Section titled “Synchronizace s externím systémem”/** * Sync document to external system * * @param OrderModel $order Order model * @param WC_Order $wc_order WC order * @param string $document_type Document type * * @return void */function sync_to_external_system( $order, $wc_order, $document_type ): void { // Příklad synchronizace s CRM $api_data = array( 'order_id' => $wc_order->get_id(), 'document_type' => $document_type, 'created_at' => current_time( 'mysql' ), );
wp_remote_post( 'https://api.your-crm.com/invoices', array( 'body' => wp_json_encode( $api_data ), 'headers' => array( 'Content-Type' => 'application/json', ), ) );}add_action( 'wpify_woo_fakturoid_document_created', 'sync_to_external_system', 10, 3 );Kde umístit kód
Section titled “Kde umístit kód”Vlastní funkci můžete vložit buď do tzv. child šablony nebo pomocí pluginu Code Snippets.