feat: Add comprehensive email flow diagnostics and logging

🔍 Email Flow Diagnostic Tool:
Created test-email-flow.php - comprehensive diagnostic dashboard:
- System status (notification mode, email channel, Action Scheduler)
- Event configuration checker
- Email queue status (wp_options)
- Action Scheduler queue status
- Recent email logs viewer
- Test actions (queue test email, process queue, test order email)
- Troubleshooting guide

📝 Enhanced Debug Logging:
Added detailed logging to EmailManager:
- Hook trigger logging
- Order validation logging
- Event enabled/disabled logging
- Email rendering status
- wp_mail() call result
- Full email flow traceability

🎯 Usage:
1. Visit: /wp-content/plugins/woonoow/test-email-flow.php
2. Check all system status indicators
3. Use test buttons to trigger emails
4. Monitor debug logs for detailed flow

📋 Logs to Watch:
[EmailManager] send_order_processing_email triggered
[EmailManager] order_processing email is disabled/enabled
[EmailManager] Sending order_processing email
[EmailManager] Email rendered successfully
[EmailManager] wp_mail called - Result: success/failed
[WooNooW MailQueue] Queued email ID
[WooNooW MailQueue] Processing email_id
[WooNooW MailQueue] Sent and deleted email ID

🚀 Troubleshooting Steps:
1. Check notification system mode (woonoow vs woocommerce)
2. Check email channel enabled
3. Check event-specific email enabled
4. Check Action Scheduler for failures
5. Check debug logs for flow
6. Test with diagnostic tool
This commit is contained in:
dwindown
2025-11-18 15:44:08 +07:00
parent f77c9b828e
commit 7394d2f213
2 changed files with 285 additions and 1 deletions

View File

@@ -115,19 +115,33 @@ class EmailManager {
* @param WC_Order $order
*/
public function send_order_processing_email($order_id, $order = null) {
if (defined('WP_DEBUG') && WP_DEBUG) {
error_log('[EmailManager] send_order_processing_email triggered for order #' . $order_id);
}
if (!$order) {
$order = wc_get_order($order_id);
}
if (!$order) {
if (defined('WP_DEBUG') && WP_DEBUG) {
error_log('[EmailManager] Order not found for ID: ' . $order_id);
}
return;
}
// Check if event is enabled
if (!$this->is_event_enabled('order_processing', 'email', 'customer')) {
if (defined('WP_DEBUG') && WP_DEBUG) {
error_log('[EmailManager] order_processing email is disabled in settings');
}
return;
}
if (defined('WP_DEBUG') && WP_DEBUG) {
error_log('[EmailManager] Sending order_processing email for order #' . $order_id);
}
// Send email
$this->send_email('order_processing', 'customer', $order);
}
@@ -364,6 +378,10 @@ class EmailManager {
* @param array $extra_data
*/
private function send_email($event_id, $recipient_type, $data, $extra_data = []) {
if (defined('WP_DEBUG') && WP_DEBUG) {
error_log('[EmailManager] send_email called - Event: ' . $event_id . ', Recipient: ' . $recipient_type);
}
// Get email renderer
$renderer = EmailRenderer::instance();
@@ -371,16 +389,27 @@ class EmailManager {
$email = $renderer->render($event_id, $recipient_type, $data, $extra_data);
if (!$email) {
if (defined('WP_DEBUG') && WP_DEBUG) {
error_log('[EmailManager] Email rendering failed for event: ' . $event_id);
}
return;
}
if (defined('WP_DEBUG') && WP_DEBUG) {
error_log('[EmailManager] Email rendered successfully - To: ' . $email['to'] . ', Subject: ' . $email['subject']);
}
// Send email via wp_mail
$headers = [
'Content-Type: text/html; charset=UTF-8',
'From: ' . get_bloginfo('name') . ' <' . get_option('admin_email') . '>',
];
wp_mail($email['to'], $email['subject'], $email['body'], $headers);
$sent = wp_mail($email['to'], $email['subject'], $email['body'], $headers);
if (defined('WP_DEBUG') && WP_DEBUG) {
error_log('[EmailManager] wp_mail called - Result: ' . ($sent ? 'success' : 'failed'));
}
// Log email sent
do_action('woonoow_email_sent', $event_id, $recipient_type, $email);