// === Add Custom Invoice Button Under Phone Number in Admin Order Page === add_action('woocommerce_admin_order_data_after_billing_address', function($order){ $order_key = $order->get_order_key(); // Add order key for public access $invoice_link = admin_url('admin-ajax.php?action=generate_custom_invoice&order_id=' . $order->get_id() . '&key=' . $order_key); echo '
'; }); // === Generate Custom Invoice (Printable HTML) === add_action('wp_ajax_generate_custom_invoice', 'generate_custom_invoice'); add_action('wp_ajax_nopriv_generate_custom_invoice', 'generate_custom_invoice'); function generate_custom_invoice() { $order_id = intval($_GET['order_id']); $key = $_GET['key'] ?? ''; $order = wc_get_order($order_id); if (!$order || $order->get_order_key() !== $key) { wp_die('Invalid invoice link.'); } // === Site Info === $site_url = preg_replace('#^https?://#', '', get_bloginfo('url')); // Clean URL // === QR Code === $invoice_link = admin_url('admin-ajax.php?action=generate_custom_invoice&order_id=' . $order->get_id() . '&key=' . $key); $qr_code_url = 'https://api.qrserver.com/v1/create-qr-code/?size=400x400&data=' . urlencode($invoice_link); // === Begin HTML Invoice === $html = '
Ship To:
'; $html .= 'Name: ' . esc_html($order->get_formatted_billing_full_name()) . '
';
$html .= 'Phone: ' . esc_html($order->get_billing_phone()) . '
';
$html .= 'Address: ' . esc_html($order->get_billing_address_1()) . '
| Item Description | Qty | Unit Price | Amount |
|---|---|---|---|
| ';
$html .= esc_html($name);
// đ SHOW SIZE UNDER PRODUCT NAME
if (!empty($size)) {
$html .= ' Size: ' . esc_html($size) . ' '; } $html .= ' |
' . esc_html($qty) . ' | ' . wc_price($price) . ' | ' . wc_price($total) . ' |
| Shipping (āĻĄā§āϞāĻŋāĻāĻžāϰāĻŋ āĻāĻžāϰā§āĻ) | ' . wc_price($shipping_total) . ' | ||
| Discount | -' . wc_price($discount_total) . ' | ||
| Total | ' . wc_price($grand_total) . ' | ||
| ' . esc_html($payment_text) . ' | |||