WC_Session_Handler::get_session_cookiepublicWC 1.0

Get the session cookie, if set. Otherwise return false.

Session cookies without a customer ID are invalid.

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

Хуков нет.

Возвращает

true|false|Массив.

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

$WC_Session_Handler = new WC_Session_Handler();
$WC_Session_Handler->get_session_cookie();

Код WC_Session_Handler::get_session_cookie() WC 10.6.2

public function get_session_cookie() {
	$cookie_value = isset( $_COOKIE[ $this->_cookie ] ) ? wc_clean( wp_unslash( (string) $_COOKIE[ $this->_cookie ] ) ) : '';

	if ( empty( $cookie_value ) ) {
		return false;
	}

	// Check if the cookie value contains '||' instead of '|' to support older versions of the cookie. This can be removed in WC 11.0.0.
	if ( strpos( $cookie_value, '||' ) !== false ) {
		$parsed_cookie = explode( '||', $cookie_value );
	} else {
		$parsed_cookie = explode( '|', $cookie_value );
	}

	if ( count( $parsed_cookie ) !== 4 ) {
		return false;
	}

	list( $customer_id, $session_expiration, $session_expiring, $cookie_hash ) = $parsed_cookie;

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

	$verify_hash = $this->verify_hash( $customer_id . '|' . $session_expiration, $cookie_hash );

	if ( ! $verify_hash ) {
		return false;
	}

	return array( $customer_id, $session_expiration, $session_expiring, $cookie_hash );
}