/* Plugin Name: WooCommerce Persian Invoice Plugin */ if (!defined('ABSPATH')) { exit; } add_action('admin_menu', 'wc_persian_invoice_menu'); add_action('admin_enqueue_scripts', 'wc_persian_invoice_enqueue'); add_action('add_meta_boxes', 'wc_persian_invoice_meta_box'); add_action('admin_init', 'wc_persian_invoice_process'); add_action('manage_shop_order_posts_custom_column', 'wc_persian_invoice_column', 10, 2); add_filter('manage_edit-shop_order_columns', 'wc_persian_invoice_columns'); function wc_persian_invoice_menu() { add_menu_page('Persian Invoice', 'Persian Invoice', 'manage_woocommerce', 'wc-persian-invoice', 'wc_persian_invoice_page'); } function wc_persian_invoice_enqueue() { wp_enqueue_style('wc-persian-invoice', plugins_url('style.css', __FILE__)); } function wc_persian_invoice_meta_box() { add_meta_box('wc-persian-invoice', 'Print Invoice', 'wc_persian_invoice_meta_box_callback', 'shop_order', 'side', 'high'); } function wc_persian_invoice_meta_box_callback($post) { echo 'Print Invoice'; } function wc_persian_invoice_columns($columns) { $new_columns = array(); foreach ($columns as $key => $value) { $new_columns[$key] = $value; if ($key === 'order_status') { $new_columns['print_invoice'] = 'Print Invoice'; } } return $new_columns; } function wc_persian_invoice_column($column, $post_id) { if ($column === 'print_invoice') { echo 'Print Invoice'; } } add_action('wp_ajax_wc_persian_invoice_generate', 'wc_persian_invoice_generate'); function wc_persian_invoice_generate() { $order_id = intval($_GET['order_id']); $order = wc_get_order($order_id); header('Content-Type: application/pdf'); header('Content-Disposition: inline; filename="invoice-' . $order_id . '.pdf"'); require_once('fpdf/fpdf.php'); $pdf = new FPDF('P', 'mm', 'A4'); $pdf->AddPage(); // Header Section $pdf->SetFont('Arial', 'B', 14); $pdf->SetTextColor(0, 0, 0); $pdf->Cell(190, 10, 'INVOICE', 0, 1, 'C'); $pdf->SetFont('Arial', '', 12); $pdf->SetFillColor(240, 240, 240); $pdf->Cell(95, 10, 'Seller Information', 1, 0, 'L', true); $pdf->Cell(95, 10, 'Buyer Information', 1, 1, 'L', true); $pdf->SetFont('Arial', '', 10); $pdf->Cell(95, 10, 'Your Company Name', 1, 0, 'L'); $pdf->Cell(95, 10, $order->get_billing_first_name() . ' ' . $order->get_billing_last_name(), 1, 1, 'L'); $pdf->Cell(95, 10, 'Address Line 1', 1, 0, 'L'); $pdf->Cell(95, 10, $order->get_billing_address_1(), 1, 1, 'L'); $pdf->Cell(95, 10, 'Phone: +123456789', 1, 0, 'L'); $pdf->Cell(95, 10, 'Phone: ' . $order->get_billing_phone(), 1, 1, 'L'); // Items Section $pdf->Ln(5); $pdf->SetFont('Arial', 'B', 10); $pdf->SetFillColor(255, 255, 0); $pdf->Cell(90, 10, 'Item', 1, 0, 'C', true); $pdf->Cell(25, 10, 'Quantity', 1, 0, 'C', true); $pdf->Cell(35, 10, 'Unit Price', 1, 0, 'C', true); $pdf->Cell(40, 10, 'Total', 1, 1, 'C', true); $pdf->SetFont('Arial', '', 10); foreach ($order->get_items() as $item) { $pdf->Cell(90, 10, $item->get_name(), 1); $pdf->Cell(25, 10, $item->get_quantity(), 1, 0, 'C'); $pdf->Cell(35, 10, wc_price($item->get_total() / $item->get_quantity()), 1, 0, 'R'); $pdf->Cell(40, 10, wc_price($item->get_total()), 1, 1, 'R'); } // Total Section $pdf->Ln(5); $pdf->SetFont('Arial', 'B', 10); $pdf->Cell(150, 10, 'Total', 1, 0, 'R'); $pdf->Cell(40, 10, wc_price($order->get_total()), 1, 1, 'R'); $pdf->Output(); exit; } function wc_persian_invoice_page() { echo '

Persian Invoice

Use this plugin to print invoices for your WooCommerce orders.

'; } قوانین ومقررات - TOOLTICK | تولتیک

قوانین ومقررات