Automattic\WooCommerce\Internal\PushNotifications\Notifications

NewReviewNotification::should_send_to_userpublicWC 10.9.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.

Method of the class: NewReviewNotification{}

No Hooks.

Returns

true|false.

Usage

$NewReviewNotification = new NewReviewNotification();
$NewReviewNotification->should_send_to_user( $pref_value ): bool;
$pref_value(mixed) (required)
The user's stored preference value, or null.

Changelog

Since 10.9.0 Introduced.

NewReviewNotification::should_send_to_user() code WC 10.9.1

public function should_send_to_user( $pref_value ): bool {
	if ( ! parent::should_send_to_user( $pref_value ) ) {
		return false;
	}

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

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

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

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

	return (int) $rating <= (int) $pref_value['max_rating'];
}