WC_Notes_Run_Db_Update::maybe_update_noticepublic staticWC 10.3.0

Checks whether the note needs an update based on the current db update status. Hooked onto the woocommerce_get_note_from_db See WC_Install{}.

Method of the class: WC_Notes_Run_Db_Update{}

No Hooks.

Returns

Note.

Usage

$result = WC_Notes_Run_Db_Update::maybe_update_notice( $note );
$note(Note) (required)
Note to check.

Changelog

Since 10.3.0 Introduced.

WC_Notes_Run_Db_Update::maybe_update_notice() code WC 10.3.3

public static function maybe_update_notice( $note ) {
	if ( ! $note instanceof Note || $note->get_name() !== self::NOTE_NAME ) {
		return $note;
	}

	// If the legacy notice is not set, hide the note. This should not normally happen, but serves as a fallback.
	if ( ! in_array( 'update', \WC_Admin_Notices::get_notices(), true ) ) {
		$note->set_status( Note::E_WC_ADMIN_NOTE_ACTIONED );
		$note->save();

		return $note;
	}

	$needs_db_update = \WC_Install::needs_db_update();

	if ( ! $needs_db_update ) {
		// If there's no need to update the database and the note has not been actioned, update it to the thank you note.
		if ( Note::E_WC_ADMIN_NOTE_ACTIONED !== $note->get_status() ) {
			self::update_done_notice( $note );
		}
	} else {
		// If a db update is needed...
		$next_scheduled_date = WC()->queue()->get_next( 'woocommerce_run_update_callback', null, 'woocommerce-db-updates' );

		if ( $next_scheduled_date ) {
			// ... and scheduled, update the note to "in progress".
			self::update_in_progress_notice( $note );
		} else {
			// ... and not scheduled, nudge to run the db update.
			self::update_needed_notice( $note );
		}
	}

	return $note;
}