WC_Session_Handler::generate_customer_id()
Generate a unique customer ID for guests, or return user ID if logged in.
Description Description
Uses Portable PHP password hashing framework to generate a unique cryptographically strong ID.
Return Return
(string)
Source Source
File: includes/class-wc-session-handler.php
public function generate_customer_id() {
$customer_id = '';
if ( is_user_logged_in() ) {
$customer_id = strval( get_current_user_id() );
}
if ( empty( $customer_id ) ) {
require_once ABSPATH . 'wp-includes/class-phpass.php';
$hasher = new PasswordHash( 8, false );
$customer_id = md5( $hasher->get_random_bytes( 32 ) );
}
return $customer_id;
}