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.

Method of the class: WC_Cart_Totals{}

No Hooks.


null. Nothing (null).


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


Since 3.2.0 Introduced.

WC_Cart_Totals::get_items_from_cart() code WC 8.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;