Automattic\WooCommerce\Internal\PushNotifications\Services

NotificationPreferencesService::get_preferencespublicWC 10.8.0

Retrieve a user's notification preferences.

Falls back to defaults for users with no stored preferences. Stored preferences are overlaid on top of the defaults so that any newer keys not yet on disk are filled in.

Method of the class: NotificationPreferencesService{}

No Hooks.

Returns

Array. array<string, mixed>> Map of preference key => sub-options.

Usage

$NotificationPreferencesService = new NotificationPreferencesService();
$NotificationPreferencesService->get_preferences( $user_id ): array;
$user_id(int) (required)
The user ID.

Changelog

Since 10.8.0 Introduced.

NotificationPreferencesService::get_preferences() code WC 10.9.1

public function get_preferences( int $user_id ): array {
	$envelope = $this->data_store->read( $user_id );

	if ( null === $envelope ) {
		return $this->get_defaults();
	}

	$stored = isset( $envelope['preferences'] ) && is_array( $envelope['preferences'] )
		? $envelope['preferences']
		: array();

	return $this->sanitize( array_replace_recursive( $this->get_defaults(), $stored ) );
}