diff --git a/plugins/woocommerce-admin/src/Notes/Notes.php b/plugins/woocommerce-admin/src/Notes/Notes.php index 4939dcdeaf6..68d9246ab5b 100644 --- a/plugins/woocommerce-admin/src/Notes/Notes.php +++ b/plugins/woocommerce-admin/src/Notes/Notes.php @@ -282,4 +282,23 @@ class Notes { } } } + + /** + * Get the status of a given note by name. + * + * @param string $note_name Name of the note. + * @return string|bool The note status. + */ + public static function get_note_status( $note_name ) { + $data_store = \WC_Data_Store::load( 'admin-note' ); + $note_ids = $data_store->get_notes_with_name( $note_name ); + + if ( empty( $note_ids ) ) { + return false; + } + + $note = self::get_note( $note_ids[0] ); + + return $note->get_status(); + } } diff --git a/plugins/woocommerce-admin/src/RemoteInboxNotifications/GetRuleProcessor.php b/plugins/woocommerce-admin/src/RemoteInboxNotifications/GetRuleProcessor.php index d21229b7e5f..d858f275e12 100644 --- a/plugins/woocommerce-admin/src/RemoteInboxNotifications/GetRuleProcessor.php +++ b/plugins/woocommerce-admin/src/RemoteInboxNotifications/GetRuleProcessor.php @@ -52,6 +52,8 @@ class GetRuleProcessor { return new BaseLocationCountryRuleProcessor(); case 'base_location_state': return new BaseLocationStateRuleProcessor(); + case 'note_status': + return new NoteStatusRuleProcessor(); } return new FailRuleProcessor(); diff --git a/plugins/woocommerce-admin/src/RemoteInboxNotifications/NoteStatusRuleProcessor.php b/plugins/woocommerce-admin/src/RemoteInboxNotifications/NoteStatusRuleProcessor.php new file mode 100644 index 00000000000..fcfaa56dbda --- /dev/null +++ b/plugins/woocommerce-admin/src/RemoteInboxNotifications/NoteStatusRuleProcessor.php @@ -0,0 +1,61 @@ +note_name ); + if ( ! $status ) { + return false; + } + + return ComparisonOperation::compare( + $status, + $rule->status, + $rule->operation + ); + } + + /** + * Validates the rule. + * + * @param object $rule The rule to validate. + * + * @return bool Pass/fail. + */ + public function validate( $rule ) { + if ( ! isset( $rule->note_name ) ) { + return false; + } + + if ( ! isset( $rule->status ) ) { + return false; + } + + if ( ! isset( $rule->operation ) ) { + return false; + } + + return true; + } +} diff --git a/plugins/woocommerce-admin/src/RemoteInboxNotifications/README.md b/plugins/woocommerce-admin/src/RemoteInboxNotifications/README.md index c47a9fabf28..d28b58ced78 100644 --- a/plugins/woocommerce-admin/src/RemoteInboxNotifications/README.md +++ b/plugins/woocommerce-admin/src/RemoteInboxNotifications/README.md @@ -368,4 +368,16 @@ This passes when the store is located in the specified state. `value` and `operation` are both required. +### Note status +This passes when the status of the specified note matches the specified status. +The below example passes when the `wc-admin-mobile-app` note has not been +actioned. +``` +{ + "type": "note_status", + "note_name": "wc-admin-mobile-app", + "status": "actioned", + "operation": "!=" +} +```