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. Ничего (null).

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

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

Код Checkout::update_customer_from_request() WC 8.6.1

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 );
		} elseif ( $this->additional_fields_controller->is_field( $key, 'address' ) ) {
			$this->additional_fields_controller->persist_field_for_customer( "/billing/$key", $value, $customer );
		}
	}

	// 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 );
		} elseif ( $this->additional_fields_controller->is_field( $key, 'address' ) ) {
			$this->additional_fields_controller->persist_field_for_customer( "/shipping/$key", $value, $customer );
		}
	}

	/**
	 * Fires when the Checkout Block/Store API updates a customer from the API request data.
	 *
	 * @since 8.2.0
	 *
	 * @param \WC_Customer $customer Customer object.
	 * @param \WP_REST_Request $request Full details about the request.
	 */
	do_action( 'woocommerce_store_api_checkout_update_customer_from_request', $customer, $request );

	$customer->save();
}