WC_Cart_Totals::get_items_from_cart()protectedWC 3.2.0

Handles a cart or order object passed in for calculation. Normalises data into the same format for use by this class.

Each item is made up of the following props, in addition to those returned by get_default_item_props() for totals.

  • key: An identifier for the item (cart item key or line item ID).
  • cart_item: For carts, the cart item from the cart which may include custom data.
  • quantity: The qty for this line.
  • price: The line price in cents.
  • product: The product object this cart item is for.

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

Хуков нет.

Возвращает

null. Ничего (null).

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

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->get_items_from_cart();

Список изменений

С версии 3.2.0 Введена.

Код WC_Cart_Totals::get_items_from_cart() WC 8.7.0

protected function get_items_from_cart() {
	$this->items = array();

	foreach ( $this->cart->get_cart() as $cart_item_key => $cart_item ) {
		$item                          = $this->get_default_item_props();
		$item->key                     = $cart_item_key;
		$item->object                  = $cart_item;
		$item->tax_class               = $cart_item['data']->get_tax_class();
		$item->taxable                 = 'taxable' === $cart_item['data']->get_tax_status();
		$item->price_includes_tax      = wc_prices_include_tax();
		$item->quantity                = $cart_item['quantity'];
		$item->price                   = wc_add_number_precision_deep( (float) $cart_item['data']->get_price() * (float) $cart_item['quantity'] );
		$item->product                 = $cart_item['data'];
		$item->tax_rates               = $this->get_item_tax_rates( $item );
		$this->items[ $cart_item_key ] = $item;
	}
}