WC_Customer_Data_Store_Session::save_to_session()publicWC 1.0

Saves all customer data to the session.

Method of the class: WC_Customer_Data_Store_Session{}

Return

null. Nothing (null).

Usage

$WC_Customer_Data_Store_Session = new WC_Customer_Data_Store_Session();
$WC_Customer_Data_Store_Session->save_to_session( $customer );
$customer(WC_Customer) (required)
Customer object.

WC_Customer_Data_Store_Session::save_to_session() code WC 9.4.2

public function save_to_session( $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;
		}
	}
	WC()->session->set( 'customer', $data );
}