Automattic\WooCommerce\Internal\PushNotifications\Notifications
Notification::get_suppression_reason
Returns which preference stops this notification reaching a user, or null where it should reach them.
$pref_value is whatever the user has stored under this notification type's preference key, or null if they have nothing stored. The NotificationPreferencesService{} stores each preference as an object so future sub-fields (thresholds, sub-toggles) can be added without bumping the schema version — today's shape is ['enabled' => bool], future shapes might add e.g. ['enabled' => true,'min_value'=> 500] for an order threshold.
Default: read the universal enabled sub-field, defaulting to true when the value is missing or has no enabled key (so newly-added notification types are opt-in by default). Subclasses override to read richer sub-fields and to consult their own resource, returning the first reason that applies.
Subclasses must keep this side-effect-free, since the NotificationProcessor{} may call it once per recipient user per notification.
Method of the class: Notification{}
No Hooks.
Returns
string|null. One of the SuppressionReason constants, or null to send.
Usage
$Notification = new Notification(); $Notification->get_suppression_reason( $pref_value ): ?string;
- $pref_value(mixed) (required)
- The user's stored preference value, or null.
Changelog
| Since 11.3.0 | Introduced. |
Notification::get_suppression_reason() Notification::get suppression reason code WC 11.3.0
public function get_suppression_reason( $pref_value ): ?string {
if ( null === $pref_value ) {
return null;
}
if ( is_array( $pref_value ) ) {
return ( $pref_value['enabled'] ?? true ) ? null : SuppressionReason::NOTIFICATIONS_OFF;
}
// Defensive fallback for unexpected scalar values; the service
// always normalises stored prefs to the array shape above.
return $pref_value ? null : SuppressionReason::NOTIFICATIONS_OFF;
}