Automattic\WooCommerce\Internal\StockNotifications\Frontend

SignupService::is_already_signed_up │ public │ WC 1.0

Get the active or pending notification for the request data.

Method of the class: SignupService{}

No Hooks.

Returns

Notification|null. The notification, or null if it doesn't exist.

Usage

$SignupService = new SignupService();
$SignupService->is_already_signed_up( $product_id, $user_id, $user_email, $posted_attributes );
$product_id(int) (required)
The product ID.
$user_id(int) (required)
The user ID.
$user_email(string) (required)
The user email.
$posted_attributes(array)
The posted attributes (Optional).
Default: array()

SignupService::is_already_signed_up() code WC 11.3.0

public function is_already_signed_up( int $product_id, int $user_id, string $user_email, array $posted_attributes = array() ) {

	$user_email = EmailNormalizer::normalize( $user_email );

	if ( empty( $product_id ) ) {
		return null;
	}

	if ( empty( $user_id ) && empty( $user_email ) ) {
		return null;
	}

	// A customer may have signed up as a guest (user_id 0) before creating an account with the same
	// email, or vice versa. Match on user ID first, then fall back to the email so both states are found.
	$identities = array();
	if ( ! empty( $user_id ) ) {
		$identities[] = array(
			'user_id'    => $user_id,
			'user_email' => '',
		);
	}
	if ( ! empty( $user_email ) ) {
		$identities[] = array(
			'user_id'    => 0,
			'user_email' => $user_email,
		);
	}

	foreach ( $identities as $identity ) {
		$notification_id = NotificationQuery::get_matching_notification_id( $product_id, $identity['user_id'], $identity['user_email'], $posted_attributes );
		if ( empty( $notification_id ) ) {
			continue;
		}

		$notification = Factory::get_notification( $notification_id );
		if ( $notification instanceof Notification ) {
			return $notification;
		}
	}

	return null;
}