WC_Session_Handler::get_session_cookie
Get the session cookie, if set. Otherwise return false.
Session cookies without a customer ID are invalid.
Method of the class: WC_Session_Handler{}
No Hooks.
Returns
true|false|Array.
Usage
$WC_Session_Handler = new WC_Session_Handler(); $WC_Session_Handler->get_session_cookie();
WC_Session_Handler::get_session_cookie() WC Session Handler::get session cookie code WC 10.3.3
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 );
}