WordPress как на ладони
Недорогой хостинг для сайтов на WordPress: wordpress.jino.ru Платформа для конвертации и монетизации трафика
функция не описана

Automattic\WooCommerce\Blocks\StoreApi\Schemas

CartSchema::get_item_response() public WC 1.0

Convert a woo cart into an object suitable for the response.

{} Это метод класса: CartSchema{}

Хуков нет.

Возвращает

Массив.

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

$CartSchema = new CartSchema();
$CartSchema->get_item_response( $cart );
$cart(\WC_Cart) (обязательный)
Cart class instance.

Код CartSchema::get_item_response() WC 4.7.1

<?php
public function get_item_response( $cart ) {
	$controller = new CartController();

	// Get cart errors first so if recalculations are performed, it's reflected in the response.
	$cart_errors = $this->get_cart_errors( $cart );

	return [
		'coupons'          => array_values( array_map( [ $this->coupon_schema, 'get_item_response' ], array_filter( $cart->get_applied_coupons() ) ) ),
		'shipping_rates'   => array_values( array_map( [ $this->shipping_rate_schema, 'get_item_response' ], $controller->get_shipping_packages() ) ),
		'shipping_address' => $this->shipping_address_schema->get_item_response( wc()->customer ),
		'items'            => array_values( array_map( [ $this->item_schema, 'get_item_response' ], array_filter( $cart->get_cart() ) ) ),
		'items_count'      => $cart->get_cart_contents_count(),
		'items_weight'     => wc_get_weight( $cart->get_cart_contents_weight(), 'g' ),
		'needs_payment'    => $cart->needs_payment(),
		'needs_shipping'   => $cart->needs_shipping(),
		'totals'           => (object) array_merge(
			$this->get_store_currency_response(),
			[
				'total_items'        => $this->prepare_money_response( $cart->get_subtotal(), wc_get_price_decimals() ),
				'total_items_tax'    => $this->prepare_money_response( $cart->get_subtotal_tax(), wc_get_price_decimals() ),
				'total_fees'         => $this->prepare_money_response( $cart->get_fee_total(), wc_get_price_decimals() ),
				'total_fees_tax'     => $this->prepare_money_response( $cart->get_fee_tax(), wc_get_price_decimals() ),
				'total_discount'     => $this->prepare_money_response( $cart->get_discount_total(), wc_get_price_decimals() ),
				'total_discount_tax' => $this->prepare_money_response( $cart->get_discount_tax(), wc_get_price_decimals() ),
				'total_shipping'     => $this->prepare_money_response( $cart->get_shipping_total(), wc_get_price_decimals() ),
				'total_shipping_tax' => $this->prepare_money_response( $cart->get_shipping_tax(), wc_get_price_decimals() ),

				// Explicitly request context='edit'; default ('view') will render total as markup.
				'total_price'        => $this->prepare_money_response( $cart->get_total( 'edit' ), wc_get_price_decimals() ),
				'total_tax'          => $this->prepare_money_response( $cart->get_total_tax(), wc_get_price_decimals() ),
				'tax_lines'          => $this->get_tax_lines( $cart ),
			]
		),
		'errors'           => $cart_errors,
	];
}