woocommerce_restored_session_data
Filters the session data when restoring from storage during initialization.
This filter allows you to:
- Modify the session data before it's loaded, including adding or removing specific session data entries
- Clear the entire session by returning an empty array
Note: If the filtered data is empty, the session will be destroyed and the guest's session cookie will be removed. This can be useful for high-traffic sites that prioritize page caching over maintaining all session data.
Usage
add_filter( 'woocommerce_restored_session_data', 'wp_kama_woocommerce_restored_session_data_filter' );
/**
* Function for `woocommerce_restored_session_data` filter-hook.
*
* @param array $session_data The session data loaded from storage.
*
* @return array
*/
function wp_kama_woocommerce_restored_session_data_filter( $session_data ){
// filter...
return $session_data;
}
- $session_data(array)
- The session data loaded from storage.
Changelog
| Since 9.9.0 | Introduced. |
Where the hook is called
woocommerce_restored_session_data
woocommerce/includes/class-wc-session-handler.php 266
$this->_data = (array) apply_filters( 'woocommerce_restored_session_data', $session_data );