Automattic\WooCommerce\Admin

PluginsHelper::should_show_notice()public staticWC 1.0

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

Метод класса: PluginsHelper{}

Хуков нет.

Возвращает

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

Использование

$result = PluginsHelper::should_show_notice( $dismiss_notice_meta );
$dismiss_notice_meta(строка) (обязательный)
User meta that includes the timestamp when a store notice was dismissed.

Код PluginsHelper::should_show_notice() WC 9.3.3

public static function should_show_notice( $dismiss_notice_meta ) {
	// 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 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;
}