WC_Checkout::update_session()protectedWC 3.0.0

Update customer and session data from the posted checkout data.

Метод класса: WC_Checkout{}

Хуков нет.

Возвращает

null. Ничего (null).

Использование

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->update_session( $data );
$data(массив) (обязательный)
Posted data.

Список изменений

С версии 3.0.0 Введена.

Код WC_Checkout::update_session() WC 8.7.0

protected function update_session( $data ) {
	// Update both shipping and billing to the passed billing address first if set.
	$address_fields = array(
		'first_name',
		'last_name',
		'company',
		'email',
		'phone',
		'address_1',
		'address_2',
		'city',
		'postcode',
		'state',
		'country',
	);

	array_walk( $address_fields, array( $this, 'set_customer_address_fields' ), $data );
	WC()->customer->save();

	// Update customer shipping and payment method to posted method.
	$chosen_shipping_methods = WC()->session->get( 'chosen_shipping_methods' );

	if ( is_array( $data['shipping_method'] ) ) {
		foreach ( $data['shipping_method'] as $i => $value ) {
			if ( ! is_string( $value ) ) {
				continue;
			}
			$chosen_shipping_methods[ $i ] = $value;
		}
	}

	WC()->session->set( 'chosen_shipping_methods', $chosen_shipping_methods );
	WC()->session->set( 'chosen_payment_method', $data['payment_method'] );

	// Update cart totals now we have customer address.
	WC()->cart->calculate_totals();
}