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.
Return
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 9.6.1
public function get_session_cookie() { $cookie_value = isset( $_COOKIE[ $this->_cookie ] ) ? wp_unslash( $_COOKIE[ $this->_cookie ] ) : false; // @codingStandardsIgnoreLine. if ( empty( $cookie_value ) || ! is_string( $cookie_value ) ) { return false; } $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; } // Validate hash. $to_hash = $customer_id . '|' . $session_expiration; $hash = hash_hmac( 'md5', $to_hash, wp_hash( $to_hash ) ); if ( empty( $cookie_hash ) || ! hash_equals( $hash, $cookie_hash ) ) { return false; } return array( $customer_id, $session_expiration, $session_expiring, $cookie_hash ); }