Automattic\WooCommerce\Internal\PushNotifications\Notifications

NewReviewNotification::get_suppression_reason │ public │ WC 11.3.0

{@inheritDoc}

Extends the base enabled-toggle check with a maximum-rating threshold. When max_rating is set in the user's preferences, reviews rated above the threshold do not trigger a notification.

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

Хуков нет.

Возвращает

string|null. One of the SuppressionReason constants, or null to send.

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

$NewReviewNotification = new NewReviewNotification();
$NewReviewNotification->get_suppression_reason( $pref_value ): ?string;
$pref_value(разное) (обязательный)
The user's stored preference value, or null.

Список изменений

С версии 11.3.0 Введена.

Код NewReviewNotification::get_suppression_reason() WC 11.3.0

public function get_suppression_reason( $pref_value ): ?string {
	$reason = parent::get_suppression_reason( $pref_value );

	if ( null !== $reason ) {
		return $reason;
	}

	if ( ! is_array( $pref_value ) || ! isset( $pref_value['max_rating'] ) ) {
		return null;
	}

	$comment = WC()->call_function( 'get_comment', $this->get_resource_id() );
	if ( ! $comment instanceof WP_Comment ) {
		return SuppressionReason::REVIEW_MISSING;
	}

	$rating = WC()->call_function( 'get_comment_meta', $this->get_resource_id(), 'rating', true );

	if ( '' === $rating ) {
		return null;
	}

	return (int) $rating <= (int) $pref_value['max_rating'] ? null : SuppressionReason::ABOVE_MAX_RATING;
}