1. Opening Problem Statement
Meet James, the customer support lead at Best Shirts Ltd., a busy online WooCommerce store. James spends several hours each day answering repetitive questions from customers about their order status and shipping details. Often, customers provide incomplete or incorrect information, forcing James to dig through the WooCommerce backend manually or toggle between the order system and shipment carrier websites. This tedious process leads to wasted time, increased response delays, and diminished customer experience.
Additionally, James must ensure that customers only access their own order information to comply with privacy rules, making the support process even more cumbersome. Without automation, James risks human errors, privacy breaches, and overtime costs due to inefficient workflows.
This exact pain motivates the workflow we explore here — an n8n automation that securely fetches WooCommerce order details and current DHL shipment status based on encrypted customer email input through a chat interface.
2. What This Automation Does
This automation transforms the way WooCommerce customer service teams handle order inquiries by:
- Securely decrypting encrypted customer emails passed via a chat interface to ensure data privacy.
- Verifying customer existence in WooCommerce using the email to fetch the customer ID.
- Retrieving all orders associated with the validated customer, ensuring no unauthorized data access.
- Extracting and merging shipment tracking data from WooCommerce order metadata.
- Querying DHL API for real-time shipment status updates for each tracking number found.
- Returning a consolidated response to the chat showing order status, shipment info, or relevant error messages.
This workflow saves numerous hours spent by support staff in manual order lookups and tracking checks, reduces human errors, and empowers customers with immediate and accurate responses through a secure chat interface.
3. Prerequisites ⚙️
- WooCommerce API account with customer and order read permissions.
- DHL API account for shipment tracking queries.
- n8n Workflow Automation Platform account (cloud or self-hosted).
- OpenAI API key for the AI-driven chat agent and contextual memory.
- Basic knowledge of JavaScript to understand encryption/decryption code nodes.
- Ability to embed a chat widget into your website to pass encrypted emails securely to the workflow.
4. Step-by-Step Guide
Step 1: Setup the Chat Trigger
In n8n, locate and add the Chat Trigger node, which listens for incoming chat requests from your website front-end. This node exposes a webhook URL where encrypted customer data will be sent.
Expected Outcome: A live webhook endpoint ready to receive encrypted chat session data, including the customer email.
Common mistake: Forgetting to set the webhook as public, which prevents external calls.
Step 2: Decrypt the Customer Email
Use the Code Node “Decrypt email address” to securely decrypt the email sent encrypted from the website using AES-256-CBC. This node:
- Extracts the IV and ciphertext from the encrypted string.
- Derives the key from a password.
- Returns decrypted email for subsequent nodes.
Paste the following JS:
const crypto = require('crypto');
const password = 'a random password';
const incomingData = $input.first().json;
function decrypt(encrypted, password) {
const parts = encrypted.split(':');
const iv = Buffer.from(parts.shift(), 'hex');
const key = crypto.scryptSync(password, 'salt', 32);
const decipher = crypto.createDecipheriv('aes-256-cbc', key, iv);
let decrypted = decipher.update(parts.join(':'), 'hex', 'utf8');
decrypted += decipher.final('utf8');
return decrypted;
}
return [{ json: {
...incomingData,
metadata: { email: decrypt(incomingData.metadata.email, password) },
}}];Expected Outcome: The decrypted email is available in the node output.
Common mistake: Using inconsistent passwords between encryption on-site and decryption here.
Step 3: Check if Email Is Provided
Drag in an If Node named “If email provided” that inspects if the email field is non-empty. If blank, route to a node that replies “No email address got provided.”
Expected Outcome: Invalid requests are handled gracefully.
Step 4: Retrieve WooCommerce Customer
Add a WooCommerce node (resource: customer, operation: getAll) to fetch the customer data using the decrypted email.
Configure the node with your WooCommerce credential and set the email filter to {{$json.email}}.
Expected Outcome: The customer data is retrieved if the email exists, otherwise an error message is sent.
Step 5: Validate if Customer Exists
Use another If Node named “If user found” to check if the customer fetch returned any data by evaluating the JSON length > 0.
If found, move forward; else, reply “No customer with that email address could be found.”
Step 6: Fetch Customer Orders via HTTP Request
Insert an HTTP Request Node named “WooCommerce Get Orders” that calls the WooCommerce orders API with the customer ID as a parameter, requesting the relevant orders.
Ensure authentication with WooCommerce credentials and pass customer ID dynamically.
Expected Outcome: The orders JSON list.
Step 7: Check if Orders Are Found
With an If Node “If order found,” verify that the orders list is not empty. If none, return “No order could be found.”
Step 8: Extract Shipment Tracking Data
Use a Set Node named “Extract Tracking Data” to filter order metadata to extract DHL tracking items stored under _wc_shipment_tracking_items.
Step 9: Check Tracking Data Presence
Use an If Node “If contains DHL data” to confirm the extracted tracking array is not empty. If empty, simply merge orders without tracking.
Step 10: Split Tracking Data and Query DHL API
Use the Split Out Node to split each tracking item, then query DHL API with each tracking number using the DHL Node.
This node fetches live shipment status for all tracking numbers found.
Step 11: Handle Missing Tracking Data
Use a Set Node “Add Error Information” to create user-friendly messages if no tracking info was found for a shipment ID.
Step 12: Aggregate DHL Data and Merge Orders
After DHL queries, aggregate the tracking data and merge it back with the order data using multiple Merge Nodes to produce a combined view.
Step 13: Send Chat Response
Finally, use a Set Node “Send Response” to send the enriched array of orders and tracking info back to the chat interface user.
Step 14: AI Agent for Conversational Handling
The heart of the workflow is the AI Agent Node powered by OpenAI GPT-4, configured with system instructions tailored for Best Shirts Ltd.’s order inquiries.
This AI maintains context through a Window Buffer Memory Node, makes API calls to WooCommerce, and returns clear, customer-friendly, factual answers inside the chat.
Step 15: Deploy Chat Widget in Website
Use the provided Respond to Webhook Node to serve an embeddable HTML chat widget. Update the webhookUrl and encrypted email in the script appropriately.
Expected Outcome: Customers access a secure chat on the website that intelligently answers order inquiries in real-time using their encrypted email.
5. Customizations ✏️
- Change Shop Name in AI Agent: In the
AI Agentnode, update thesystemMessagefield to reflect your store’s name and customer service policy. - Use Alternative Shipping APIs: Replace or extend the
DHL Nodewith UPS or FedEx nodes if you ship with different carriers. - Adjust Encryption Password: Update the password string in the
Encrypt emailandDecrypt email addresscode nodes to match your secure backend encryption key. - Modify Chat Interface: Edit the
Respond to Webhooknode’s HTML to change chat window appearance or behavior.
6. Troubleshooting 🔧
Problem: “No customer with that email address could be found.”
Cause: Email decryption failed or incorrect email sent.
Solution: Verify password matches encryption key and that email is correctly encrypted and passed in the chat metadata.
Problem: “No order could be found.”
Cause: Customer exists but has no orders.
Solution: Confirm orders exist in WooCommerce and that API credentials have order read permissions.
Problem: DHL API call returns errors or no data.
Cause: Invalid tracking number format or DHL API credentials issues.
Solution: Double-check DHL tracking numbers extracted and validate API keys and permissions.
7. Pre-Production Checklist ✅
- Test with a real encrypted customer email known in WooCommerce.
- Ensure WooCommerce API credentials have correct permissions.
- Confirm DHL API integration is functional and returns expected data.
- Validate AI Agent responses with various order scenarios.
- Backup your workflow and credentials before production.
8. Deployment Guide
Activate the workflow in your n8n environment by enabling all nodes and setting your production webhook URLs.
Embed the chat widget on your website using the HTML served by “Respond to Webhook.”
Monitor usage from n8n’s execution logs and error outputs to ensure smooth operation.
9. FAQs
- Can I use another shipping provider instead of DHL? Yes, by replacing the DHL node with an appropriate API node for your carrier.
- Does this consume significant OpenAI API credits? The usage is moderate; only relevant chat interactions trigger AI calls.
- Is my data secure with encrypted emails? Yes, encryption ensures that only authorized queries with the right key are processed.
- Can this workflow handle hundreds of orders? Yes, but monitor API rate limits for WooCommerce and DHL.
10. Conclusion
By following this guide, you’ve implemented a powerful n8n workflow that transforms customer order support by securely linking WooCommerce order data with real-time DHL tracking inside an AI-powered chat interface.
This reduces the manual workload of your support team by hours daily and eliminates privacy risks by using encrypted email verification.
Next steps could be to add more carriers, handle returns processing, or integrate a CRM for richer customer insights.
Let’s make WooCommerce order inquiries effortless and secure for both customers and your support team!