diff --git a/includes/Api/NotificationsController.php b/includes/Api/NotificationsController.php index 2727410..0437129 100644 --- a/includes/Api/NotificationsController.php +++ b/includes/Api/NotificationsController.php @@ -203,7 +203,7 @@ class NotificationsController { 'category' => 'orders', 'wc_email' => 'new_order', 'enabled' => true, - 'channels' => $settings['order_placed'] ?? ['email' => ['enabled' => true, 'recipient' => 'admin']], + 'channels' => $settings['order_placed']['channels'] ?? ['email' => ['enabled' => false, 'recipient' => 'admin'], 'push' => ['enabled' => false, 'recipient' => 'admin']], ], [ 'id' => 'order_processing', @@ -212,7 +212,7 @@ class NotificationsController { 'category' => 'orders', 'wc_email' => 'customer_processing_order', 'enabled' => true, - 'channels' => $settings['order_processing'] ?? ['email' => ['enabled' => true, 'recipient' => 'customer']], + 'channels' => $settings['order_processing']['channels'] ?? ['email' => ['enabled' => false, 'recipient' => 'customer'], 'push' => ['enabled' => false, 'recipient' => 'customer']], ], [ 'id' => 'order_completed', @@ -221,7 +221,7 @@ class NotificationsController { 'category' => 'orders', 'wc_email' => 'customer_completed_order', 'enabled' => true, - 'channels' => $settings['order_completed'] ?? ['email' => ['enabled' => true, 'recipient' => 'customer']], + 'channels' => $settings['order_completed']['channels'] ?? ['email' => ['enabled' => false, 'recipient' => 'customer'], 'push' => ['enabled' => false, 'recipient' => 'customer']], ], [ 'id' => 'order_cancelled', @@ -230,7 +230,7 @@ class NotificationsController { 'category' => 'orders', 'wc_email' => 'cancelled_order', 'enabled' => true, - 'channels' => $settings['order_cancelled'] ?? ['email' => ['enabled' => true, 'recipient' => 'admin']], + 'channels' => $settings['order_cancelled']['channels'] ?? ['email' => ['enabled' => false, 'recipient' => 'admin'], 'push' => ['enabled' => false, 'recipient' => 'admin']], ], [ 'id' => 'order_refunded', @@ -239,7 +239,7 @@ class NotificationsController { 'category' => 'orders', 'wc_email' => 'customer_refunded_order', 'enabled' => true, - 'channels' => $settings['order_refunded'] ?? ['email' => ['enabled' => true, 'recipient' => 'customer']], + 'channels' => $settings['order_refunded']['channels'] ?? ['email' => ['enabled' => false, 'recipient' => 'customer'], 'push' => ['enabled' => false, 'recipient' => 'customer']], ], ], 'products' => [ @@ -250,7 +250,7 @@ class NotificationsController { 'category' => 'products', 'wc_email' => 'low_stock', 'enabled' => true, - 'channels' => $settings['low_stock'] ?? ['email' => ['enabled' => true, 'recipient' => 'admin']], + 'channels' => $settings['low_stock']['channels'] ?? ['email' => ['enabled' => false, 'recipient' => 'admin'], 'push' => ['enabled' => false, 'recipient' => 'admin']], ], [ 'id' => 'out_of_stock', @@ -259,7 +259,7 @@ class NotificationsController { 'category' => 'products', 'wc_email' => 'no_stock', 'enabled' => true, - 'channels' => $settings['out_of_stock'] ?? ['email' => ['enabled' => true, 'recipient' => 'admin']], + 'channels' => $settings['out_of_stock']['channels'] ?? ['email' => ['enabled' => false, 'recipient' => 'admin'], 'push' => ['enabled' => false, 'recipient' => 'admin']], ], ], 'customers' => [ @@ -270,7 +270,7 @@ class NotificationsController { 'category' => 'customers', 'wc_email' => 'customer_new_account', 'enabled' => true, - 'channels' => $settings['new_customer'] ?? ['email' => ['enabled' => true, 'recipient' => 'customer']], + 'channels' => $settings['new_customer']['channels'] ?? ['email' => ['enabled' => false, 'recipient' => 'customer'], 'push' => ['enabled' => false, 'recipient' => 'customer']], ], [ 'id' => 'customer_note', @@ -279,7 +279,7 @@ class NotificationsController { 'category' => 'customers', 'wc_email' => 'customer_note', 'enabled' => true, - 'channels' => $settings['customer_note'] ?? ['email' => ['enabled' => true, 'recipient' => 'customer']], + 'channels' => $settings['customer_note']['channels'] ?? ['email' => ['enabled' => false, 'recipient' => 'customer'], 'push' => ['enabled' => false, 'recipient' => 'customer']], ], ], ]; @@ -574,10 +574,11 @@ class NotificationsController { } // Only allow toggling built-in channels + $option_key = ''; if ($channel_id === 'email') { - update_option('woonoow_email_notifications_enabled', (bool) $enabled); + $option_key = 'woonoow_email_notifications_enabled'; } elseif ($channel_id === 'push') { - update_option('woonoow_push_notifications_enabled', (bool) $enabled); + $option_key = 'woonoow_push_notifications_enabled'; } else { return new WP_Error( 'invalid_channel', @@ -586,6 +587,12 @@ class NotificationsController { ); } + // Update the option + update_option($option_key, (bool) $enabled, false); // false = don't autoload + + // Verify the update + $verified = get_option($option_key); + return new WP_REST_Response([ 'success' => true, 'message' => sprintf( @@ -593,6 +600,8 @@ class NotificationsController { $channel_id === 'email' ? __('Email', 'woonoow') : __('Push', 'woonoow'), $enabled ? __('enabled', 'woonoow') : __('disabled', 'woonoow') ), + 'channelId' => $channel_id, + 'enabled' => (bool) $verified, ], 200); } }