WC_Session_Handler::is_customer_guest()privateWC 1.0

Checks if this is an auto-generated customer ID.

{} Это метод класса: WC_Session_Handler{}

Хуков нет.

Возвращает

true|false. Whether customer ID is randomly generated.

Использование

// private - только в коде основоного (родительского) класса
$result = $this->is_customer_guest( $customer_id );
$customer_id(строка|int) (обязательный)
Customer ID to check.

Код WC_Session_Handler::is_customer_guest() WC 6.4.1

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;
}