diff --git a/mailer.js b/mailer.js
index af8f7f6..59cc28d 100644
--- a/mailer.js
+++ b/mailer.js
@@ -74,6 +74,12 @@ 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;
+
let billingAddressHtml = '';
if (billing.first_name || billing.last_name) {
billingAddressHtml += `${billing.first_name || ''} ${billing.last_name || ''}
`;
@@ -87,6 +93,9 @@ const sendEmailWithAttachment = async (toEmail, orderData, pdfBuffer, shippingLa
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';
diff --git a/pdfGenerator.js b/pdfGenerator.js
index 555838a..fe430a0 100644
--- a/pdfGenerator.js
+++ b/pdfGenerator.js
@@ -132,6 +132,12 @@ 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;
+
doc.fontSize(11)
.font('Helvetica-Bold')
.fillColor(primaryColor)
@@ -168,6 +174,10 @@ const generateInvoicePDF = async (orderData) => {
}
if (billing.phone || orderData.phone) {
doc.text(billing.phone || orderData.phone, 40, billTextY);
+ billTextY += 13;
+ }
+ if (customContactNumber) {
+ doc.text(`Contact: ${customContactNumber}`, 40, billTextY);
}
// Order Details (Right)
diff --git a/server.js b/server.js
index 7646c54..6fee522 100644
--- a/server.js
+++ b/server.js
@@ -206,6 +206,15 @@ app.post('/create-order', async (req, res) => {
}
};
+ if (customerData.contact_phone || customerData.contactNumber || customerData.contact_number) {
+ orderPayload.order.note_attributes = [
+ {
+ name: 'Contact Number',
+ value: customerData.contact_phone || customerData.contactNumber || customerData.contact_number
+ }
+ ];
+ }
+
const shopifyResponse = await fetch(`https://${process.env.SHOPIFY_STORE_DOMAIN}/admin/api/2024-01/orders.json`, {
method: 'POST',
headers: {