Automattic\WooCommerce\StoreApi\Routes\V1
CheckoutOrder::update_billing_address
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()
Метод класса: CheckoutOrder{}
Хуки из метода
Возвращает
null. Ничего (null).
Использование
// private - только в коде основоного (родительского) класса $result = $this->update_billing_address( $request );
- $request(WP_REST_Request) (обязательный)
- Full details about the request.
Код CheckoutOrder::update_billing_address() CheckoutOrder::update billing address WC 10.5.1
private function update_billing_address( \WP_REST_Request $request ) {
$customer = wc()->customer;
$billing = $request['billing_address'];
$shipping = $request['shipping_address'];
// Billing address is a required field.
foreach ( $billing 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 = $shipping ?? $billing;
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 );
}
}
/**
* 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->set_billing_address( $billing );
$this->order->set_shipping_address( $shipping );
$this->order->save();
$this->order->calculate_totals();
}