WC_Customer_Data_Store_Session::save_to_session()publicWC 1.0

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 8.7.0

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 = wp_json_encode(
				array_filter(
					$customer->get_meta_data(),
					function( $meta_data ) use ( $allowed_keys ) {
						return in_array( $meta_data->key, $allowed_keys, true );
					}
				)
			);
		} else {
			$session_value = $customer->{"get_$function_key"}( 'edit' );
		}
		$data[ $session_key ] = (string) $session_value;
	}
	WC()->session->set( 'customer', $data );
}