Add prefix to guest user id generation

This commit is contained in:
dinamiko 2022-01-10 12:51:56 +01:00
parent e68ff57572
commit c2834df32f
2 changed files with 5 additions and 2 deletions

View file

@ -108,7 +108,6 @@ class IdentityToken {
$customer_id = $this->customer_repository->customer_id_for_user( ( $user_id ) );
if ( 0 === $user_id ) {
$customer_id = uniqid();
WC()->session->set( 'ppcp_guest_customer_id', $customer_id );
}

View file

@ -37,9 +37,13 @@ class CustomerRepository {
* @return string
*/
public function customer_id_for_user( int $user_id ): string {
if ( 0 === $user_id ) {
return $this->prefix . uniqid();
}
$guest_customer_id = get_user_meta( $user_id, 'ppcp_guest_customer_id', true );
if ( $guest_customer_id ) {
return $this->prefix . $guest_customer_id;
return $guest_customer_id;
}
return $this->prefix . (string) $user_id;