diff --git a/mailer.js b/mailer.js index 322a974..59cc28d 100644 --- a/mailer.js +++ b/mailer.js @@ -72,58 +72,30 @@ 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 || {}; + const contactNumber = orderData.note_attributes?.find?.((attr) => attr.name === 'Contact Number')?.value + || orderData.attributes?.['Contact Number']?.contact_phone + || orderData.attributes?.['Contact Number'] + || orderData.contact_phone + || orderData.attributes?.contact_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']; - -// 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 || ''}
`; -} - -if (billing.address1) { - billingAddressHtml += `${billing.address1}
`; -} - -if (billing.address2) { - billingAddressHtml += `${billing.address2}
`; -} - -if (billing.city || billing.province || billing.zip) { - billingAddressHtml += `${billing.city || ''} ${billing.province || ''} ${billing.zip || ''}
`; -} - -if (billing.country) { - billingAddressHtml += `${billing.country}
`; -} - -// Show WhatsApp -if (whatsappNumber) { - billingAddressHtml += `WhatsApp: ${whatsappNumber}`; -} - -// Show Contact Number -if (contactNumber) { - billingAddressHtml += `
Contact Number: ${contactNumber}`; -} + let billingAddressHtml = ''; + if (billing.first_name || billing.last_name) { + billingAddressHtml += `${billing.first_name || ''} ${billing.last_name || ''}
`; + } + if (billing.address1) billingAddressHtml += `${billing.address1}
`; + if (billing.address2) billingAddressHtml += `${billing.address2}
`; + if (billing.city || billing.province || billing.zip) { + billingAddressHtml += `${billing.city || ''} ${billing.province || ''} ${billing.zip || ''}
`; + } + if (billing.country) billingAddressHtml += `${billing.country}
`; + if (billing.phone || orderData.phone) { + billingAddressHtml += `${billing.phone || orderData.phone}`; + } + if (contactNumber) { + billingAddressHtml += `
Contact: ${contactNumber}`; + } const paymentMethod = orderData.gateway || 'Request Quote'; const shippingMethod = orderData.shipping_lines?.[0]?.title || 'Economy';