From af2a3d3dd551d744c94e67b480b226ef815592aa Mon Sep 17 00:00:00 2001 From: dwindown Date: Tue, 18 Nov 2025 18:25:27 +0700 Subject: [PATCH] fix: Enable email notifications by default with default templates MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 🐛 CRITICAL FIX - Root Cause Found: Problem 1: Events Not Enabled by Default - is_event_enabled() returned false if not configured - Required explicit admin configuration - Plugin didn't work out-of-the-box Solution: - Enable email notifications by default if not configured - Allow plugin to work with default templates - Users can still disable via admin if needed Problem 2: Default Templates Not Loading - EmailRenderer called get_template() with only 2 args - Missing $recipient_type parameter - Default template lookup failed Solution: - Pass recipient_type to get_template() - Proper default template lookup - Added debug logging for template resolution 📝 Changes: 1. EmailManager::is_event_enabled() - Returns true by default for email channel - Logs when using default (not configured) - Respects explicit disable if configured 2. EmailRenderer::get_template_settings() - Pass recipient_type to TemplateProvider - Log template found/not found - Proper default template resolution 🎯 Result: - Plugin works out-of-the-box - Default templates used if not customized - Email notifications sent without configuration - Users can still customize in admin ✅ Expected Behavior: 1. Install plugin 2. Create order 3. Email sent automatically (default template) 4. Customize templates in admin (optional) This fixes the issue where check-settings.php showed: - Email: ✗ NOT CONFIGURED - Templates: 0 Now it will use defaults and send emails! --- includes/Core/Notifications/EmailManager.php | 11 ++++++++++- includes/Core/Notifications/EmailRenderer.php | 11 +++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/includes/Core/Notifications/EmailManager.php b/includes/Core/Notifications/EmailManager.php index 9a6b797..1eb6643 100644 --- a/includes/Core/Notifications/EmailManager.php +++ b/includes/Core/Notifications/EmailManager.php @@ -361,11 +361,20 @@ class EmailManager { private function is_event_enabled($event_id, $channel_id, $recipient_type) { $settings = get_option('woonoow_notification_settings', []); - // Check if event exists and channel is enabled + // Check if event exists and channel is configured if (isset($settings['events'][$event_id]['channels'][$channel_id])) { return $settings['events'][$event_id]['channels'][$channel_id]['enabled'] ?? false; } + // Default: enable email notifications if not explicitly configured + // This allows the plugin to work out-of-the-box with default templates + if ($channel_id === 'email') { + if (defined('WP_DEBUG') && WP_DEBUG) { + error_log('[EmailManager] Event not configured, using default: enabled'); + } + return true; // Enable by default + } + return false; } diff --git a/includes/Core/Notifications/EmailRenderer.php b/includes/Core/Notifications/EmailRenderer.php index a7a8a05..e8383d3 100644 --- a/includes/Core/Notifications/EmailRenderer.php +++ b/includes/Core/Notifications/EmailRenderer.php @@ -81,13 +81,20 @@ class EmailRenderer { * @return array|null */ private function get_template_settings($event_id, $recipient_type) { - // Get saved template - $template = TemplateProvider::get_template($event_id, 'email'); + // Get saved template (with recipient_type for proper default template lookup) + $template = TemplateProvider::get_template($event_id, 'email', $recipient_type); if (!$template) { + if (defined('WP_DEBUG') && WP_DEBUG) { + error_log('[EmailRenderer] No template found for event: ' . $event_id . ', recipient: ' . $recipient_type); + } return null; } + if (defined('WP_DEBUG') && WP_DEBUG) { + error_log('[EmailRenderer] Template found - Subject: ' . ($template['subject'] ?? 'no subject')); + } + // Get design template preference $settings = get_option('woonoow_notification_settings', []); $design = $settings['email_design_template'] ?? 'modern';