'email', 'label' => __('Email', 'woonoow'), 'icon' => 'mail', 'builtin' => true, 'enabled' => true, ]); // Register default notification events self::register_default_events(); // Allow addons to register their channels add_action('woonoow_register_notification_channels', [__CLASS__, 'allow_addon_registration']); } /** * Register a notification channel * * @param string $id Channel ID * @param array $args Channel arguments */ public static function register_channel($id, $args = []) { $defaults = [ 'id' => $id, 'label' => ucfirst($id), 'icon' => 'bell', 'builtin' => false, 'enabled' => false, 'addon' => '', ]; self::$channels[$id] = wp_parse_args($args, $defaults); } /** * Get all registered channels * * @return array */ public static function get_channels() { return apply_filters('woonoow_notification_channels', self::$channels); } /** * Register default notification events */ private static function register_default_events() { // Order events self::register_event('order_placed', [ 'label' => __('Order Placed', 'woonoow'), 'description' => __('When a new order is placed', 'woonoow'), 'category' => 'orders', 'wc_email' => 'new_order', // Maps to WC_Email_New_Order ]); self::register_event('order_processing', [ 'label' => __('Order Processing', 'woonoow'), 'description' => __('When order status changes to processing', 'woonoow'), 'category' => 'orders', 'wc_email' => 'customer_processing_order', ]); self::register_event('order_completed', [ 'label' => __('Order Completed', 'woonoow'), 'description' => __('When order is marked as completed', 'woonoow'), 'category' => 'orders', 'wc_email' => 'customer_completed_order', ]); self::register_event('order_cancelled', [ 'label' => __('Order Cancelled', 'woonoow'), 'description' => __('When order is cancelled', 'woonoow'), 'category' => 'orders', 'wc_email' => 'cancelled_order', ]); self::register_event('order_refunded', [ 'label' => __('Order Refunded', 'woonoow'), 'description' => __('When order is refunded', 'woonoow'), 'category' => 'orders', 'wc_email' => 'customer_refunded_order', ]); // Product events self::register_event('low_stock', [ 'label' => __('Low Stock Alert', 'woonoow'), 'description' => __('When product stock is low', 'woonoow'), 'category' => 'products', 'wc_email' => 'low_stock', ]); self::register_event('out_of_stock', [ 'label' => __('Out of Stock Alert', 'woonoow'), 'description' => __('When product is out of stock', 'woonoow'), 'category' => 'products', 'wc_email' => 'no_stock', ]); // Customer events self::register_event('new_customer', [ 'label' => __('New Customer', 'woonoow'), 'description' => __('When a new customer registers', 'woonoow'), 'category' => 'customers', 'wc_email' => 'customer_new_account', ]); self::register_event('customer_note', [ 'label' => __('Customer Note Added', 'woonoow'), 'description' => __('When a note is added to customer order', 'woonoow'), 'category' => 'customers', 'wc_email' => 'customer_note', ]); } /** * Register a notification event * * @param string $id Event ID * @param array $args Event arguments */ public static function register_event($id, $args = []) { $defaults = [ 'id' => $id, 'label' => ucfirst(str_replace('_', ' ', $id)), 'description' => '', 'category' => 'general', 'wc_email' => '', 'channels' => [], ]; self::$events[$id] = wp_parse_args($args, $defaults); } /** * Get all registered events * * @return array */ public static function get_events() { return apply_filters('woonoow_notification_events', self::$events); } /** * Get events by category * * @param string $category Category name * @return array */ public static function get_events_by_category($category) { $events = self::get_events(); return array_filter($events, function($event) use ($category) { return $event['category'] === $category; }); } /** * Send notification * * @param string $event_id Event ID * @param array $data Notification data * @param array $channels Channels to use (default: from settings) */ public static function send($event_id, $data = [], $channels = null) { // Get event configuration $event = self::$events[$event_id] ?? null; if (!$event) { return; } // Get channels from settings if not specified if ($channels === null) { $settings = NotificationSettingsProvider::get_event_settings($event_id); $channels = $settings['channels'] ?? ['email']; } // Send via each enabled channel foreach ($channels as $channel_id) { // Email is handled by WooCommerce, skip it if ($channel_id === 'email') { continue; } // Fire action for addon channels do_action("woonoow_notification_send_{$channel_id}", $event_id, $data); } } /** * Allow addons to register channels */ public static function allow_addon_registration() { // Addons hook into this to register their channels // Example: add_action('woonoow_register_notification_channels', function() { // NotificationManager::register_channel('whatsapp', [...]); // }); } }