WC_Session_Handler::is_customer_guest()privateWC 1.0

Checks if this is an auto-generated customer ID.

Method of the class: WC_Session_Handler{}

No Hooks.

Return

true|false. Whether customer ID is randomly generated.

Usage

// private - for code of main (parent) class only
$result = $this->is_customer_guest( $customer_id );
$customer_id(string|int) (required)
Customer ID to check.

WC_Session_Handler::is_customer_guest() code WC 8.7.0

private function is_customer_guest( $customer_id ) {
	$customer_id = strval( $customer_id );

	if ( empty( $customer_id ) ) {
		return true;
	}

	if ( 't_' === substr( $customer_id, 0, 2 ) ) {
		return true;
	}

	/**
	 * Legacy checks. This is to handle sessions that were created from a previous release.
	 * Maybe we can get rid of them after a few releases.
	 */

	// Almost all random $customer_ids will have some letters in it, while all actual ids will be integers.
	if ( strval( (int) $customer_id ) !== $customer_id ) {
		return true;
	}

	// Performance hack to potentially save a DB query, when same user as $customer_id is logged in.
	if ( is_user_logged_in() && strval( get_current_user_id() ) === $customer_id ) {
		return false;
	} else {
		$customer = new WC_Customer( $customer_id );

		if ( 0 === $customer->get_id() ) {
			return true;
		}
	}

	return false;
}