WC_Customer_Data_Store_Session::save_to_session
Saves all customer data to the session.
Метод класса: WC_Customer_Data_Store_Session{}
Хуки из метода
Возвращает
null
. Ничего (null).
Использование
$WC_Customer_Data_Store_Session = new WC_Customer_Data_Store_Session(); $WC_Customer_Data_Store_Session->save_to_session( $customer );
- $customer(WC_Customer) (обязательный)
- Customer object.
Код WC_Customer_Data_Store_Session::save_to_session() WC Customer Data Store Session::save to session WC 9.9.5
public function save_to_session( $customer ) { if ( ! WC()->session ) { wc_doing_it_wrong( __METHOD__, __( 'WC_Session is not available, customer data cannot be saved to session.', 'woocommerce' ), '9.8.0' ); return; } $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 ); }