Email invoice delivery has a 20-25% open rate, while WhatsApp achieves 98%. Automating WHMCS invoice delivery via WhatsApp can boost your payment collection rates by 40-60% and reduce payment delays significantly.
Quick Benefits
- 98% message delivery and open rates
- Instant notifications with payment links
- 40-60% improvement in payment collection
- Reduced manual follow-ups
- Better customer experience
Why WhatsApp for Invoice Delivery?
Email Problems
- • 20-25% open rates
- • Spam folder issues
- • Delayed delivery
- • Less mobile-friendly
WhatsApp Advantages
- • 98% open rates
- • Instant delivery
- • Mobile-first experience
- • Direct payment access
Step-by-Step Implementation
Prerequisites
- • WHMCS 7.x or higher
- • WhatsApp Business API access
- • Valid customer phone numbers
- • Basic PHP knowledge
Method 1: Using WHMCS Hooks
Create a custom hook that triggers when an invoice is generated and sends it via WhatsApp API.
<?php
// File: includes/hooks/whatsapp_invoice.php
use WHMCS\Database\Capsule;
add_hook('InvoiceCreated', 1, function($vars) {
$invoiceId = $vars['invoiceid'];
// Get invoice details
$invoice = localAPI('GetInvoice', {
'invoiceid' => $invoiceId
});
// Get client details
$client = localAPI('GetClientsDetails', {
'clientid' => $invoice['userid']
});
// Format phone number (ensure country code)
$phone = formatPhoneNumber($client['phonenumber']);
if (!empty($phone)) {
// Create WhatsApp message
$message = createInvoiceMessage($invoice, $client);
// Send WhatsApp message
sendWhatsAppMessage($phone, $message);
// Log the action
logActivity("WhatsApp invoice sent to $phone for Invoice #$invoiceId");
}
});
function createInvoiceMessage($invoice, $client) {
$companyName = \WHMCS\Config\Setting::getValue('CompanyName');
$currencyCode = $invoice['currencycode'];
$message = "🧾 *Invoice from $companyName*\n\n";
$message .= "Hi " . $client['firstname'] . ",\n\n";
$message .= "Your invoice #" . $invoice['invoicenum'] . " is ready!\n";
$message .= " Amount: " . $currencyCode . " " . $invoice['total'] . "\n";
$message .= "📅 Due Date: " . $invoice['duedate'] . "\n\n";
$message .= " *Pay Now:* " . $invoice['paymentlink'] . "\n\n";
$message .= "Need help? Reply to this message or contact support.\n";
$message .= "\nThank you! 🙏";
return $message;
}
function formatPhoneNumber($phone) {
// Remove all non-numeric characters
$phone = preg_replace('/[^0-9]/', '', $phone);
// Add country code if missing (example: +1 for US)
if (strlen($phone) == 10) {
$phone = '1' . $phone; // US/Canada
}
return $phone;
}
function sendWhatsAppMessage($phone, $message) {
$apiUrl = 'https://api.whatsapp.com/send-message'; // Replace with your API
$accessToken = 'your_whatsapp_access_token';
$data = {
'messaging_product' => 'whatsapp',
'recipient_type' => 'individual',
'to' => $phone,
'type' => 'text',
'text' => {
'body' => $message
}
};
$headers = {
'Authorization: Bearer ' . $accessToken,
'Content-Type: application/json'
};
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $apiUrl);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
return json_decode($response, true);
}
?> Method 2: Using Third-Party Services
Services like Twilio, MessageBird, or Wati provide easier integration with pre-approved templates.
Twilio Integration Example
function sendTwilioWhatsApp($phone, $message) {
require_once 'vendor/autoload.php';
$sid = 'your_twilio_sid';
$token = 'your_twilio_token';
$client = new \Twilio\Rest\Client($sid, $token);
try {
$message = $client->messages->create(
"whatsapp:+$phone",
{
'from' => 'whatsapp:+14155238886', // Twilio Sandbox
'body' => $message
}
);
return true;
} catch (Exception $e) {
logActivity("WhatsApp error: " . $e->getMessage());
return false;
}
} Advanced Features
1. Template-Based Messages
For WhatsApp Business API, use approved message templates for better delivery rates.
Template Structure
- • Header: Company logo/name
- • Body: Invoice details
- • Footer: Support contact
- • Button: Pay Now (URL)
Approval Tips
- • Use business-appropriate language
- • Include opt-out option
- • Avoid promotional content
- • Follow WhatsApp guidelines
2. Conditional Sending
// Only send WhatsApp for invoices above certain amount
add_hook('InvoiceCreated', 1, function($vars) {
$invoice = localAPI('GetInvoice', {'invoiceid' => $vars['invoiceid']});
// Only send for invoices > $50
if ($invoice['total'] > 50) {
// Send WhatsApp
sendInvoiceWhatsApp($invoice);
}
// Or check client preference
$client = localAPI('GetClientsDetails', {'clientid' => $invoice['userid']});
if (isset($client['customfields']['WhatsApp Notifications']) &&
$client['customfields']['WhatsApp Notifications'] == 'Yes') {
sendInvoiceWhatsApp($invoice);
}
}); 3. Multi-Language Support
Send messages in the client's preferred language based on their profile settings.
function getLocalizedMessage($template, $language, $variables) {
$messages = {
'en' => "Hi {name}, your invoice #{invoice} for ${amount} is ready. Pay: {link}",
'es' => "Hola {name}, tu factura #{invoice} por ${amount} está lista. Pagar: {link}",
'fr' => "Salut {name}, votre facture #{invoice} de ${amount} est prête. Payer: {link}"
};
$message = $messages[$language] ?? $messages['en'];
foreach ($variables as $key => $value) {
$message = str_replace('{' . $key . '}', $value, $message);
}
return $message;
} Testing & Deployment
Testing Checklist
- 1. Test with your own phone number first
- 2. Verify message formatting and links
- 3. Test payment link functionality
- 4. Check international phone number formats
- 5. Verify hook triggers on invoice creation
- 6. Test error handling for invalid numbers
Production Deployment
Phase 1
Deploy to staging environment and test with sample data
Phase 2
Beta test with 10-20 trusted customers
Phase 3
Full production rollout with monitoring
Best Practices & Tips
Do's
- • Get explicit consent for WhatsApp messages
- • Use approved message templates
- • Include clear payment instructions
- • Provide customer support contact
- • Log all WhatsApp activities
- • Test thoroughly before production
- • Monitor delivery rates and errors
Don'ts
- • Don't send promotional content in invoices
- • Don't spam customers with repeated messages
- • Don't use unapproved message formats
- • Don't ignore WhatsApp policy violations
- • Don't send messages without consent
- • Don't forget to handle opt-outs
- • Don't ignore international number formats
Expected Results
Common Issues & Solutions
Phone Number Formatting Issues
Problem: Messages fail due to incorrect phone number format
Solution: Implement robust phone number validation and formatting
API Rate Limits
Problem: WhatsApp API rate limits cause message failures
Solution: Implement message queuing and retry mechanisms
Template Rejections
Problem: WhatsApp rejects custom message templates
Solution: Follow WhatsApp Business API guidelines strictly
Conclusion
Automating WHMCS invoice delivery via WhatsApp is a game-changer for payment collection. With 98% open rates and instant delivery, you'll see significant improvements in cash flow and customer satisfaction. The initial setup effort pays for itself within weeks through improved collection rates and reduced manual follow-ups.
Key Takeaways
- • WhatsApp delivers 98% vs 20% email open rates
- • Expect 40-60% improvement in payment collection
- • Use WHMCS hooks for seamless integration
- • Always get customer consent before sending
- • Test thoroughly before production deployment
Need WhatsApp Invoice Automation?
I help hosting companies set up automated WhatsApp invoice delivery systems that boost payment rates by 40-60%. Get a custom solution tailored to your WHMCS setup.
About Shahid Malla
ExpertFull Stack Developer with 10+ years of experience in WHMCS development, WordPress, and server management. Trusted by 600+ clients worldwide for hosting automation and custom solutions.