Automattic\WooCommerce\Internal\PushNotifications\Services
NotificationPreferencesService::save_preferences
Persist a partial update to a user's notification preferences.
Unknown top-level keys and unknown sub-fields per key are dropped. The merged result is wrapped in the current versioned envelope and handed to the data store.
Method of the class: NotificationPreferencesService{}
No Hooks.
Returns
Array
Usage
$NotificationPreferencesService = new NotificationPreferencesService(); $NotificationPreferencesService->save_preferences( $user_id, $preferences ): array;
- $user_id(int) (required)
- The user ID.
- $preferences(array) (required)
- .
Changelog
| Since 10.8.0 | Introduced. |
NotificationPreferencesService::save_preferences() NotificationPreferencesService::save preferences code WC 10.9.1
public function save_preferences( int $user_id, array $preferences ): array {
$current = $this->get_preferences( $user_id );
$merged = $this->sanitize( array_replace_recursive( $current, $preferences ) );
// Data store throws WC_Data_Exception on real failure; let it propagate.
$this->data_store->write(
$user_id,
array(
'schema_version' => NotificationPreferencesDataStore::CURRENT_SCHEMA_VERSION,
'preferences' => $merged,
)
);
return $merged;
}