Automattic\WooCommerce\Admin

PluginsHelper::should_show_noticepublic staticWC 1.0

Determine whether a specific notice should be shown to the current user.

Method of the class: PluginsHelper{}

No Hooks.

Returns

true|false. True if the notice should be shown, false otherwise.

Usage

$result = PluginsHelper::should_show_notice( $dismiss_notice_meta, $show_after_one_month );
$dismiss_notice_meta(string) (required)
User meta that includes the timestamp when a store notice was dismissed.
$show_after_one_month(true|false)
Show the notices dismissed earlier than one month.
Default: true

PluginsHelper::should_show_notice() code WC 9.9.4

public static function should_show_notice( $dismiss_notice_meta, $show_after_one_month = true ) {
	// Get the current user ID.
	$user_id = get_current_user_id();

	// Get the timestamp when the notice was dismissed.
	$dismissed_timestamp = get_user_meta( $user_id, $dismiss_notice_meta, true );

	if ( ! $show_after_one_month ) {
		return empty( $dismissed_timestamp );
	}

	// If the notice was dismissed within the last month, do not show it.
	if ( ! empty( $dismissed_timestamp ) && ( time() - $dismissed_timestamp ) < 30 * DAY_IN_SECONDS ) {
		return false;
	}

	// If the notice was dismissed more than a month ago, delete the meta value and show the notice.
	if ( ! empty( $dismissed_timestamp ) ) {
		delete_user_meta( $user_id, $dismiss_notice_meta );
	}

	return true;
}