WC_Session_Handler::is_session_cookie_valid()privateWC 1.0

Checks if session cookie is expired, or belongs to a logged out user.

Method of the class: WC_Session_Handler{}

No Hooks.

Return

true|false. Whether session cookie is valid.

Usage

// private - for code of main (parent) class only
$result = $this->is_session_cookie_valid();

WC_Session_Handler::is_session_cookie_valid() code WC 9.3.1

private function is_session_cookie_valid() {
	// If session is expired, session cookie is invalid.
	if ( time() > $this->_session_expiration ) {
		return false;
	}

	// If user has logged out, session cookie is invalid.
	if ( ! is_user_logged_in() && ! $this->is_customer_guest( $this->_customer_id ) ) {
		return false;
	}

	// Session from a different user is not valid. (Although from a guest user will be valid).
	if ( is_user_logged_in() && ! $this->is_customer_guest( $this->_customer_id ) && strval( get_current_user_id() ) !== $this->_customer_id ) {
		return false;
	}

	return true;
}