Automattic\WooCommerce\Internal\StockNotifications\Frontend
SignupService::is_already_signed_up
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() SignupService::is already signed up code WC 11.2.1
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 );
}
if ( ! empty( $user_email ) ) {
$identities[] = array( 'user_email' => $user_email );
}
foreach ( $identities as $identity ) {
$notifications = NotificationQuery::get_notifications(
array_merge(
$identity,
array(
'product_id' => $product_id,
'status' => array( NotificationStatus::ACTIVE, NotificationStatus::PENDING ),
'order_by' => array( 'id' => 'DESC' ),
'return' => 'objects',
)
)
);
foreach ( $notifications as $notification ) {
if ( $notification instanceof Notification && $this->matches_posted_attributes( $notification, $posted_attributes ) ) {
return $notification;
}
}
}
return null;
}