// === 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 Invoice

'; }); // === 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 = 'Invoice #'. esc_html($order->get_order_number()) .''; $html .= ''; // === Header with Logo + URL + QR Code === $html .= '
'; // Left: Invoice # $html .= '

Invoice #' . esc_html($order->get_order_number()) . '

'; // Center: QR Code $html .= '
'; $html .= '
Invoice QR Code
'; $html .= '
'; // Right: Logo + URL + Address + Phone $html .= '
Site Logo
' . esc_html($site_url) . '
Zirani, Ashulia, Savar, Dhaka -1349
01741281698
'; $html .= '
'; // === Billing Info === $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()) . '

'; // === Items Table === $html .= ''; foreach ($order->get_items() as $item) { $product = $item->get_product(); $price = $product ? wc_get_price_excluding_tax($product) : 0; $qty = $item->get_quantity(); $total = $price * $qty; $name = $item->get_name(); if ($product) { $name = 'ID:' . $product->get_id() . ', ' . $name; } // ✅ GET SIZE FROM ORDER ITEM META $size = $item->get_meta('Size'); $html .= ''; } // === Totals === $shipping_total = $order->get_shipping_total(); $discount_total = $order->get_discount_total(); $grand_total = $order->get_total(); $html .= ''; $html .= ''; $html .= ''; // === Payment Method (COD / MFS) === $custom_payment = strtolower($order->get_meta('custom_payment_method')); if ($custom_payment === 'cod') { $payment_text = 'Cash on delivery (āĻĒāĻŖā§āϝ āĻšāĻžāϤ⧇ āĻĒ⧇āϝāĻŧ⧇ āĻŽā§‚āĻ˛ā§āϝ āĻĒāϰāĻŋāĻļā§‹āϧ āĻ•āϰ⧁āύ)'; } elseif ($custom_payment === 'mfs') { $payment_text = 'Paid via MFS (bKash)'; } else { $payment_text = 'Payment: Unknown'; } $html .= ''; $html .= '
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) . '
'; $html .= ''; $html .= ''; /* $html .= '
'; */ echo $html; exit; } https://moonscollections.com/wp-sitemap-posts-page-1.xmlhttps://moonscollections.com/wp-sitemap-posts-product-1.xmlhttps://moonscollections.com/wp-sitemap-taxonomies-product_cat-1.xmlhttps://moonscollections.com/wp-sitemap-taxonomies-product_tag-1.xmlhttps://moonscollections.com/wp-sitemap-users-1.xml