Automattic\WooCommerce\StoreApi\Routes\V1

CheckoutOrder::update_billing_address │ private │ WC 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.

Method of the class: CheckoutOrder{}

Returns

null. Nothing (null).

Usage

// private - for code of main (parent) class only
$result = $this->update_billing_address( $request );
$request(WP_REST_Request) (required)
Full details about the request.

CheckoutOrder::update_billing_address() code WC 11.3.0

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

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

	$shipping = $this->order_controller->update_existing_order_addresses( $this->order, $billing, $request['shipping_address'] );

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

	// When the order keeps its own shipping address, the customer's shipping follows billing.
	foreach ( $shipping ?? $billing 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();
	$this->validate_order_was_saved();
}