WC_Customer_Data_Store_Session::get_customer_session_data
Get the customer data to store in the session.
Method of the class: WC_Customer_Data_Store_Session{}
Hooks from the method
Returns
Array.
Usage
// private - for code of main (parent) class only $result = $this->get_customer_session_data( $customer );
- $customer(WC_Customer) (required)
- Customer object.
WC_Customer_Data_Store_Session::get_customer_session_data() WC Customer Data Store Session::get customer session data code WC 10.3.3
private function get_customer_session_data( $customer ) {
$data = array();
foreach ( $this->session_keys as $session_key ) {
$function_key = $session_key;
if ( 'billing_' === substr( $session_key, 0, 8 ) ) {
$session_key = str_replace( 'billing_', '', $session_key );
}
if ( 'meta_data' === $session_key ) {
/**
* Filter the allowed session meta data keys.
*
* If the customer object contains any meta data with these keys, it will be stored within the WooCommerce session.
*
* @since 8.7.0
* @param array $allowed_keys The allowed meta data keys.
* @param WC_Customer $customer The customer object.
*/
$allowed_keys = apply_filters( 'woocommerce_customer_allowed_session_meta_keys', array(), $customer );
$session_value = array();
foreach ( $customer->get_meta_data() as $meta_data ) {
if ( in_array( $meta_data->key, $allowed_keys, true ) ) {
$session_value[] = array(
'key' => $meta_data->key,
'value' => $meta_data->value,
);
}
}
$data['meta_data'] = $session_value;
} else {
$session_value = $customer->{"get_$function_key"}( 'edit' );
$data[ $session_key ] = (string) $session_value;
}
}
return $data;
}