$note->set_name( self::NOTE_NAME ); $note->set_source( 'woocommerce-admin' ); $note_action = self::get_note_action_for_milestone( $current_milestone ); $note->add_action( $note_action['name'], $note_action['label'], $note_action['query'] ); return $note; } /** * Checks if a note can and should be added. * * @return bool */ public function can_be_added() { // If the milestone notes have been disabled via filter, bail. if ( ! $this->are_milestones_enabled() ) { return false; } $last_milestone = $this->get_last_milestone(); $current_milestone = $this->get_current_milestone(); if ( $current_milestone <= $last_milestone ) { return false; } return true; } /** * Add milestone notes for other significant thresholds. */ public function possibly_add_note() { if ( ! self::can_be_added() ) { return; } $current_milestone = $this->get_current_milestone(); $this->set_last_milestone( $current_milestone ); // We only want one milestone note at any time. Notes::delete_notes_with_name( self::NOTE_NAME ); $note = $this->get_note_by_milestone( $current_milestone ); $note->save(); } }