diff --git a/mailer.js b/mailer.js
index e0e9a0c..85f1de9 100644
--- a/mailer.js
+++ b/mailer.js
@@ -74,11 +74,8 @@ const sendEmailWithAttachment = async (toEmail, orderData, pdfBuffer, shippingLa
// --- 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;
+ const whatsappNumber = orderData.note_attributes?.find?.((attr) => attr.name === 'WhatsApp Number')?.value;
+ const contactNumber = billing.phone || orderData.phone;
let billingAddressHtml = '';
if (billing.first_name || billing.last_name) {
@@ -90,12 +87,12 @@ const sendEmailWithAttachment = async (toEmail, orderData, pdfBuffer, shippingLa
billingAddressHtml += `${billing.city || ''} ${billing.province || ''} ${billing.zip || ''}
`;
}
if (billing.country) billingAddressHtml += `${billing.country}
`;
- if (contactNumber) {
- billingAddressHtml += `WhatsApp: ${contactNumber}`;
+ if (whatsappNumber) {
+ billingAddressHtml += `WhatsApp: ${whatsappNumber}`;
}
- if (billing.phone || orderData.phone) {
- if (contactNumber) billingAddressHtml += `
`;
- billingAddressHtml += `Contact Number: ${billing.phone || orderData.phone}`;
+ if (contactNumber) {
+ if (whatsappNumber) billingAddressHtml += `
`;
+ billingAddressHtml += `Contact Number: ${contactNumber}`;
}
const paymentMethod = orderData.gateway || 'Request Quote';
diff --git a/pdfGenerator.js b/pdfGenerator.js
index d0cda6f..69b9d7c 100644
--- a/pdfGenerator.js
+++ b/pdfGenerator.js
@@ -132,11 +132,7 @@ const generateInvoicePDF = async (orderData) => {
// Bill To (Left)
const billing = orderData.billing_address || {};
- const customContactNumber = 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;
+ const whatsappNumber = orderData.note_attributes?.find?.((attr) => attr.name === 'WhatsApp Number')?.value;
doc.fontSize(11)
.font('Helvetica-Bold')
@@ -172,8 +168,8 @@ const generateInvoicePDF = async (orderData) => {
doc.text(orderData.email || orderData.contact_email, 40, billTextY);
billTextY += 13;
}
- if (customContactNumber) {
- doc.text(`WhatsApp: ${customContactNumber}`, 40, billTextY);
+ if (whatsappNumber) {
+ doc.text(`WhatsApp: ${whatsappNumber}`, 40, billTextY);
billTextY += 13;
}
if (billing.phone || orderData.phone) {
diff --git a/server.js b/server.js
index ad3f866..9a86668 100644
--- a/server.js
+++ b/server.js
@@ -210,11 +210,12 @@ app.post('/create-order', async (req, res) => {
}
};
- if (customerData.contact_phone || customerData.contactNumber || customerData.contact_number) {
+ const whatsappNumber = customerData.whatsapp_number || customerData.contact_phone || customerData.contactNumber;
+ if (whatsappNumber) {
orderPayload.order.note_attributes = [
{
- name: 'Contact Number',
- value: customerData.contact_phone || customerData.contactNumber || customerData.contact_number
+ name: 'WhatsApp Number',
+ value: whatsappNumber
}
];
}