mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-08-30 05:00:51 +08:00
Update the registration logic
When notes are not enabled, we need to unregister/delete them if they were previously registered
This commit is contained in:
parent
63ecb23039
commit
95e85ec51c
1 changed files with 18 additions and 0 deletions
|
@ -29,6 +29,11 @@ class InboxNoteRegistrar {
|
||||||
|
|
||||||
public function register(): void {
|
public function register(): void {
|
||||||
foreach ( $this->inbox_notes as $inbox_note ) {
|
foreach ( $this->inbox_notes as $inbox_note ) {
|
||||||
|
if ( ! $inbox_note->is_enabled() ) {
|
||||||
|
$this->unregister( $inbox_note->name() );
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
$inbox_note_name = $inbox_note->name();
|
$inbox_note_name = $inbox_note->name();
|
||||||
|
|
||||||
if ( Notes::get_note_by_name( $inbox_note_name ) ) {
|
if ( Notes::get_note_by_name( $inbox_note_name ) ) {
|
||||||
|
@ -56,4 +61,17 @@ class InboxNoteRegistrar {
|
||||||
$note->save();
|
$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 );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue