Automattic\WooCommerce\StoreApi\Routes\V1

CheckoutOrder::update_billing_addressprivateWC 1.0

Applies the billing and shipping address from the request to the order and customer.

The address is set on the order and validated before anything is persisted, so a rejected request cannot mutate the order or the customer. wc()->customer is saved on shutdown (see WooCommerce::initialize_cart()), so its address fields are only set once validation passes.

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

Возвращает

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

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

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

Код CheckoutOrder::update_billing_address() WC 11.0.1

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

	// Billing address is a required field.
	$billing = $request['billing_address'];

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

	$this->order->set_billing_address( $billing );
	$this->order->set_shipping_address( $shipping );
	$this->order_controller->validate_existing_order_before_update( $this->order );

	// Update customer object with validated order addresses.
	foreach ( $billing as $key => $value ) {
		if ( is_callable( [ $customer, "set_billing_$key" ] ) ) {
			$customer->{"set_billing_$key"}( $value );
		}
	}

	foreach ( $shipping as $key => $value ) {
		if ( is_callable( [ $customer, "set_shipping_$key" ] ) ) {
			$customer->{"set_shipping_$key"}( $value );
		}
	}

	/**
	 * 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();
	$this->order->save();
	$this->order->calculate_totals();
}