Automattic\WooCommerce\StoreApi\Routes\V1

CartUpdateCustomer::get_route_post_response()protectedWC 1.0

Handle the request and return a valid response for this endpoint.

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

Возвращает

\WP_REST_Response.

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

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->get_route_post_response( $request );
$request(\WP_REST_Request) (обязательный)
Request object.

Код CartUpdateCustomer::get_route_post_response() WC 7.1.0

protected function get_route_post_response( \WP_REST_Request $request ) {
	$cart     = $this->cart_controller->get_cart_instance();
	$billing  = $request['billing_address'] ?? [];
	$shipping = $request['shipping_address'] ?? [];
	$customer = wc()->customer;

	if ( ! $cart->needs_shipping() && ! isset( $request['shipping_address'] ) ) {
		// If the cart does not need shipping, shipping address is forced to match billing address unless defined.
		$shipping = $request['billing_address'] ?? $this->get_customer_billing_address( $customer );
	}

	$customer->set_props(
		array(
			'billing_first_name'  => $billing['first_name'] ?? null,
			'billing_last_name'   => $billing['last_name'] ?? null,
			'billing_company'     => $billing['company'] ?? null,
			'billing_address_1'   => $billing['address_1'] ?? null,
			'billing_address_2'   => $billing['address_2'] ?? null,
			'billing_city'        => $billing['city'] ?? null,
			'billing_state'       => $billing['state'] ?? null,
			'billing_postcode'    => $billing['postcode'] ?? null,
			'billing_country'     => $billing['country'] ?? null,
			'billing_phone'       => $billing['phone'] ?? null,
			'billing_email'       => $billing['email'] ?? null,
			'shipping_first_name' => $shipping['first_name'] ?? null,
			'shipping_last_name'  => $shipping['last_name'] ?? null,
			'shipping_company'    => $shipping['company'] ?? null,
			'shipping_address_1'  => $shipping['address_1'] ?? null,
			'shipping_address_2'  => $shipping['address_2'] ?? null,
			'shipping_city'       => $shipping['city'] ?? null,
			'shipping_state'      => $shipping['state'] ?? null,
			'shipping_postcode'   => $shipping['postcode'] ?? null,
			'shipping_country'    => $shipping['country'] ?? null,
			'shipping_phone'      => $shipping['phone'] ?? null,
		)
	);

	wc_do_deprecated_action(
		'woocommerce_blocks_cart_update_customer_from_request',
		array(
			$customer,
			$request,
		),
		'7.2.0',
		'woocommerce_store_api_cart_update_customer_from_request',
		'This action was deprecated in WooCommerce Blocks version 7.2.0. Please use woocommerce_store_api_cart_update_customer_from_request instead.'
	);

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

	$customer->save();

	$this->calculate_totals();

	return rest_ensure_response( $this->schema->get_item_response( $cart ) );
}