WC_Session_Handler::is_session_cookie_validprivateWC 1.0

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

Method of the class: WC_Session_Handler{}

No Hooks.

Returns

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 10.3.3

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->get_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->get_customer_id() ) && (string) get_current_user_id() !== $this->get_customer_id() ) {
		return false;
	}

	return true;
}