Automattic\WooCommerce\StoreApi\Routes\V1

Checkout::update_customer_from_request()privateWC 1.0

Updates the current customer session using data from the request (e.g. address data).

Address session data is synced to the order itself later on by OrderController::update_order_from_cart()

{} Это метод класса: Checkout{}

Хуков нет.

Возвращает

null. Ничего.

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

// private - только в коде основоного (родительского) класса
$result = $this->update_customer_from_request( $request );
$request(\WP_REST_Request) (обязательный)
Full details about the request.

Код Checkout::update_customer_from_request() WC 6.8.0

private function update_customer_from_request( \WP_REST_Request $request ) {
	$customer = wc()->customer;

	// Billing address is a required field.
	foreach ( $request['billing_address'] as $key => $value ) {
		if ( is_callable( [ $customer, "set_billing_$key" ] ) ) {
			$customer->{"set_billing_$key"}( $value );
		}
	}

	// If shipping address (optional field) was not provided, set it to the given billing address (required field).
	$shipping_address_values = $request['shipping_address'] ?? $request['billing_address'];

	foreach ( $shipping_address_values as $key => $value ) {
		if ( is_callable( [ $customer, "set_shipping_$key" ] ) ) {
			$customer->{"set_shipping_$key"}( $value );
		} elseif ( 'phone' === $key ) {
			$customer->update_meta_data( 'shipping_phone', $value );
		}
	}

	$customer->save();
}