Automattic\WooCommerce\Internal\StockNotifications\Frontend
SignupService::is_already_signed_up
Get the active 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 10.3.6
public function is_already_signed_up( int $product_id, int $user_id, string $user_email, array $posted_attributes = array() ) {
if ( empty( $product_id ) ) {
return null;
}
if ( empty( $user_id ) && empty( $user_email ) ) {
return null;
}
$found = false;
if ( ! empty( $user_id ) ) {
$found = NotificationQuery::notification_exists_by_user_id( $product_id, $user_id );
} else {
$found = NotificationQuery::notification_exists_by_email( $product_id, $user_email );
}
if ( ! $found ) {
return null;
}
$query_args = array( 'product_id' => $product_id );
if ( ! empty( $user_id ) ) {
$query_args['user_id'] = $user_id;
} else {
$query_args['user_email'] = $user_email;
}
$query_args['return'] = 'ids';
$query_args['limit'] = 1;
if ( ! empty( $posted_attributes ) ) {
// Hint: We need to compare the posted attributes with the stored attributes to handle variations with "any" attributes.
$query_args['meta_query'] = array( // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query
array(
'key' => 'posted_attributes',
'value' => maybe_serialize( $posted_attributes ),
'compare' => '=',
),
);
}
$ids = NotificationQuery::get_notifications( $query_args );
if ( empty( $ids ) || ! is_numeric( $ids[0] ) ) {
return null;
}
$notification = Factory::get_notification( $ids[0] );
if ( ! $notification ) {
return null;
}
return $notification;
}