diff --git a/mailer.js b/mailer.js
index a07a747..322a974 100644
--- a/mailer.js
+++ b/mailer.js
@@ -72,42 +72,58 @@ const sendEmailWithAttachment = async (toEmail, orderData, pdfBuffer, shippingLa
`;
}
- // --- 3. Billing Address Details HTML ---
- const billing = orderData.billing_address || {};
+// --- 3. Billing Address Details HTML ---
+const billing = orderData.billing_address || {};
- // Get separate numbers
- const contactNumber = orderData.contact_number || orderData.phone;
+// Contact Number (from Contact field only)
+const contactNumber =
+ orderData.note_attributes?.find?.(
+ (attr) => attr.name === 'Contact Number'
+ )?.value ||
+ orderData.attributes?.['Contact Number']?.contact_phone ||
+ orderData.attributes?.['Contact Number'];
- const whatsappNumber =
- orderData.whatsapp_number ||
- orderData.attributes?.['Whatsapp Number'];
+// WhatsApp Number
+const whatsappNumber =
+ orderData.note_attributes?.find?.(
+ (attr) => attr.name === 'Whatsapp Number'
+ )?.value ||
+ orderData.attributes?.['Whatsapp Number'] ||
+ billing.phone ||
+ orderData.phone;
- let billingAddressHtml = '';
- if (billing.first_name || billing.last_name) {
- billingAddressHtml += `${billing.first_name || ''} ${billing.last_name || ''}
`;
- }
+let billingAddressHtml = '';
- if (billing.address1) billingAddressHtml += `${billing.address1}
`;
- if (billing.address2) billingAddressHtml += `${billing.address2}
`;
+if (billing.first_name || billing.last_name) {
+ billingAddressHtml += `${billing.first_name || ''} ${billing.last_name || ''}
`;
+}
- if (billing.city || billing.province || billing.zip) {
- billingAddressHtml += `${billing.city || ''} ${billing.province || ''} ${billing.zip || ''}
`;
- }
+if (billing.address1) {
+ billingAddressHtml += `${billing.address1}
`;
+}
- if (billing.country) {
- billingAddressHtml += `${billing.country}
`;
- }
+if (billing.address2) {
+ billingAddressHtml += `${billing.address2}
`;
+}
- // Show contact number
- if (contactNumber) {
- billingAddressHtml += `Contact: ${contactNumber}
`;
- }
+if (billing.city || billing.province || billing.zip) {
+ billingAddressHtml += `${billing.city || ''} ${billing.province || ''} ${billing.zip || ''}
`;
+}
- // Show WhatsApp number separately
- if (whatsappNumber) {
- billingAddressHtml += `WhatsApp: ${whatsappNumber}`;
- }
+if (billing.country) {
+ billingAddressHtml += `${billing.country}
`;
+}
+
+// Show WhatsApp
+if (whatsappNumber) {
+ billingAddressHtml += `WhatsApp: ${whatsappNumber}`;
+}
+
+// Show Contact Number
+if (contactNumber) {
+ billingAddressHtml += `
Contact Number: ${contactNumber}`;
+}
const paymentMethod = orderData.gateway || 'Request Quote';
const shippingMethod = orderData.shipping_lines?.[0]?.title || 'Economy';