Automattic\WooCommerce\Blocks\StoreApi\Routes
CartUpdateCustomer::get_route_post_response() protected WC 1.0
Handle the request and return a valid response for this endpoint.
{} It's a method of the class: CartUpdateCustomer{}
No Hooks.
Return
\WP_REST_Response.
Usage
// protected - for code of main (parent) or child class $result = $this->get_route_post_response( \WP_REST_Request $request );
- \WP_REST_Request $request (required)
- -
Code of CartUpdateCustomer::get_route_post_response() CartUpdateCustomer::get route post response WC 5.0.0
protected function get_route_post_response( \WP_REST_Request $request ) {
$controller = new CartController();
$cart = $controller->get_cart_instance();
$billing = isset( $request['billing_address'] ) ? $this->prepare_address_fields( $request['billing_address'], wc()->countries->get_allowed_countries() ) : [];
$shipping = isset( $request['shipping_address'] ) ? $this->prepare_address_fields( $request['shipping_address'], wc()->countries->get_shipping_countries() ) : [];
if ( ! $cart->needs_shipping() ) {
$shipping = $billing;
}
wc()->customer->set_props(
array(
'billing_first_name' => isset( $billing['first_name'] ) ? $billing['first_name'] : null,
'billing_last_name' => isset( $billing['last_name'] ) ? $billing['last_name'] : null,
'billing_address_1' => isset( $billing['address_1'] ) ? $billing['address_1'] : null,
'billing_address_2' => isset( $billing['address_2'] ) ? $billing['address_2'] : null,
'billing_city' => isset( $billing['city'] ) ? $billing['city'] : null,
'billing_state' => isset( $billing['state'] ) ? $billing['state'] : null,
'billing_postcode' => isset( $billing['postcode'] ) ? $billing['postcode'] : null,
'billing_country' => isset( $billing['country'] ) ? $billing['country'] : null,
'billing_email' => isset( $request['billing_address'], $request['billing_address']['email'] ) ? $request['billing_address']['email'] : null,
'billing_phone' => isset( $request['billing_address'], $request['billing_address']['phone'] ) ? $request['billing_address']['phone'] : null,
'shipping_first_name' => isset( $shipping['first_name'] ) ? $shipping['first_name'] : null,
'shipping_last_name' => isset( $shipping['last_name'] ) ? $shipping['last_name'] : null,
'shipping_address_1' => isset( $shipping['address_1'] ) ? $shipping['address_1'] : null,
'shipping_address_2' => isset( $shipping['address_2'] ) ? $shipping['address_2'] : null,
'shipping_city' => isset( $shipping['city'] ) ? $shipping['city'] : null,
'shipping_state' => isset( $shipping['state'] ) ? $shipping['state'] : null,
'shipping_postcode' => isset( $shipping['postcode'] ) ? $shipping['postcode'] : null,
'shipping_country' => isset( $shipping['country'] ) ? $shipping['country'] : null,
)
);
wc()->customer->save();
$cart->calculate_shipping();
$cart->calculate_totals();
return rest_ensure_response( $this->schema->get_item_response( $cart ) );
}