From 95e85ec51ce7e3a215ca0289eff890485336b3fe Mon Sep 17 00:00:00 2001 From: Narek Zakarian Date: Fri, 15 Aug 2025 20:32:22 +0400 Subject: [PATCH] Update the registration logic When notes are not enabled, we need to unregister/delete them if they were previously registered --- .../WcInboxNotes/InboxNoteRegistrar.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/modules/ppcp-wc-gateway/src/Settings/WcInboxNotes/InboxNoteRegistrar.php b/modules/ppcp-wc-gateway/src/Settings/WcInboxNotes/InboxNoteRegistrar.php index 8a0b6509d..f9e523481 100644 --- a/modules/ppcp-wc-gateway/src/Settings/WcInboxNotes/InboxNoteRegistrar.php +++ b/modules/ppcp-wc-gateway/src/Settings/WcInboxNotes/InboxNoteRegistrar.php @@ -29,6 +29,11 @@ class InboxNoteRegistrar { public function register(): void { foreach ( $this->inbox_notes as $inbox_note ) { + if ( ! $inbox_note->is_enabled() ) { + $this->unregister( $inbox_note->name() ); + continue; + } + $inbox_note_name = $inbox_note->name(); if ( Notes::get_note_by_name( $inbox_note_name ) ) { @@ -56,4 +61,17 @@ class InboxNoteRegistrar { $note->save(); } } + + public function unregister( string $inbox_note_name ): void { + $data_store = Notes::load_data_store(); + $existing_note_ids = $data_store->get_notes_with_name( $inbox_note_name ); + + foreach ( $existing_note_ids as $note_id ) { + $note = Notes::get_note( $note_id ); + + if ( $note ) { + $data_store->delete( $note ); + } + } + } }