add_order_note( sprintf( __( '8Digits Factura: Error al generar factura - %s', '8digits-factura-for-woocommerce' ), $result->get_error_message() ) ); return; } $order->add_order_note( sprintf( __( '8Digits Factura: Factura generada - %s', '8digits-factura-for-woocommerce' ), $result['invoice_number'] ) ); } /** * Register invoice meta box on the admin order edit screen. */ public function add_invoice_meta_box(): void { $screen = wc_get_container()->get( \Automattic\WooCommerce\Internal\DataStores\Orders\CustomOrdersTableController::class )->custom_orders_table_usage_is_enabled() ? wc_get_page_screen_id( 'shop-order' ) : 'shop_order'; add_meta_box( 'eightdigits_factura_invoice', __( '8Digits Factura - Factura', '8digits-factura-for-woocommerce' ), array( $this, 'render_invoice_meta_box' ), $screen, 'side', 'high' ); } /** * Render the invoice meta box content. * * @param WP_Post|WC_Order $post_or_order */ public function render_invoice_meta_box( $post_or_order ): void { $order = $post_or_order instanceof WC_Order ? $post_or_order : wc_get_order( $post_or_order->ID ); if ( ! $order ) { return; } $invoice = EightDigits_Factura_Invoice::get_by_order( $order->get_id(), 'invoice' ); ?>
get_customer_id() === $current_user_id; if ( ! $is_admin && ! $is_owner ) { wp_die( esc_html__( 'No tiene permiso para descargar esta factura.', '8digits-factura-for-woocommerce' ) ); } $pdf_path = $invoice['pdf_path']; if ( ! file_exists( $pdf_path ) ) { $pdf_generator = new EightDigits_Factura_PDF(); $pdf_path = $pdf_generator->generate( $order, $invoice['invoice_number'], (string) $invoice['invoice_type'], (string) $invoice['invoice_date'] ); if ( is_wp_error( $pdf_path ) ) { wp_die( esc_html__( 'No se pudo generar el PDF.', '8digits-factura-for-woocommerce' ) ); } global $wpdb; $table = $wpdb->prefix . 'eightdigits_factura_invoices'; // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery $wpdb->update( $table, array( 'pdf_path' => $pdf_path ), array( 'id' => $invoice_id ), array( '%s' ), array( '%d' ) ); } $filename = basename( $pdf_path ); header( 'Content-Type: application/pdf' ); header( 'Content-Disposition: attachment; filename="' . $filename . '"' ); header( 'Content-Length: ' . filesize( $pdf_path ) ); header( 'Cache-Control: private, no-cache, no-store, must-revalidate' ); readfile( $pdf_path ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_readfile -- Streams a PDF directly to the browser. exit; } }