Automattic\WooCommerce\Internal\Admin\Notes

MarketingJetpack::possibly_add_note()public staticWC 1.0

Maybe add a note on Jetpack Backups for Jetpack sites older than a week without Backups.

Method of the class: MarketingJetpack{}

No Hooks.

Return

null. Nothing (null).

Usage

$result = MarketingJetpack::possibly_add_note();

MarketingJetpack::possibly_add_note() code WC 8.7.0

public static function possibly_add_note() {
	/**
	 * Check if Jetpack is installed.
	 */
	$installed_plugins = PluginsHelper::get_installed_plugin_slugs();
	if ( ! in_array( 'jetpack', $installed_plugins, true ) ) {
		return;
	}

	$data_store = \WC_Data_Store::load( 'admin-note' );

	// Do we already have this note?
	$note_ids = $data_store->get_notes_with_name( self::NOTE_NAME );
	if ( ! empty( $note_ids ) ) {

		$note_id = array_pop( $note_ids );
		$note    = Notes::get_note( $note_id );
		if ( false === $note ) {
			return;
		}

		// If Jetpack Backups was purchased after the note was created, mark this note as actioned.
		if ( self::has_backups() && Note::E_WC_ADMIN_NOTE_ACTIONED !== $note->get_status() ) {
			$note->set_status( Note::E_WC_ADMIN_NOTE_ACTIONED );
			$note->save();
		}

		return;
	}

	// Check requirements.
	if ( ! self::is_wc_admin_active_in_date_range( 'week-1-4', DAY_IN_SECONDS * 3 ) || ! self::can_be_added() || self::has_backups() ) {
		return;
	}

	// Add note.
	$note = self::get_note();
	$note->save();
}