WC_Session_Handler::get_session
Returns the session.
Метод класса: WC_Session_Handler{}
Хуков нет.
Возвращает
Разное. Returns either the session data or the default value. Returns false if WP setup is in progress.
Использование
$WC_Session_Handler = new WC_Session_Handler(); $WC_Session_Handler->get_session( $customer_id, $default_value );
- $customer_id(строка) (обязательный)
- Customer ID.
- $default_value(разное)
- Default session value.
По умолчанию: false
Код WC_Session_Handler::get_session() WC Session Handler::get session WC 10.4.3
public function get_session( $customer_id, $default_value = false ) {
global $wpdb;
if ( Constants::is_defined( 'WP_SETUP_CONFIG' ) ) {
return $default_value;
}
// Try to get it from the cache, it will return false if not present or if object cache not in use.
$value = wp_cache_get( $this->get_cache_prefix() . $customer_id, WC_SESSION_CACHE_GROUP );
if ( false === $value ) {
$value = $wpdb->get_var( $wpdb->prepare( 'SELECT session_value FROM %i WHERE session_key = %s', $this->_table, $customer_id ) );
if ( is_null( $value ) ) {
$value = $default_value;
}
$cache_duration = $this->_session_expiration - time();
if ( 0 < $cache_duration ) {
wp_cache_add( $this->get_cache_prefix() . $customer_id, $value, WC_SESSION_CACHE_GROUP, $cache_duration );
}
}
return maybe_unserialize( $value );
}