WordPress at Your Fingertips
function is not described

WC_Cart_Totals::get_items_from_cart() protected WC 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.

{} It's a method of the class: WC_Cart_Totals{}

No Hooks.

Return

null. Nothing.

Usage

// protected - for code of main (parent) or child class
$result = $this->get_items_from_cart();

Changelog

Since 3.2.0 Introduced.

Code of WC_Cart_Totals::get_items_from_cart() WC 5.9.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;
	}
}