WordPress at Your Fingertips
function is not described

WC_Discounts::set_items_from_cart() public WC 3.2.0

Normalise cart items which will be discounted.

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

No Hooks.

Return

null. Nothing.

Usage

$WC_Discounts = new WC_Discounts();
$WC_Discounts->set_items_from_cart( $cart );
$cart(WC_Cart) (required)
Cart object.

Changelog

Since 3.2.0 Introduced.

Code of WC_Discounts::set_items_from_cart() WC 5.6.0

public function set_items_from_cart( $cart ) {
	$this->items     = array();
	$this->discounts = array();

	if ( ! is_a( $cart, 'WC_Cart' ) ) {
		return;
	}

	$this->object = $cart;

	foreach ( $cart->get_cart() as $key => $cart_item ) {
		$item                = new stdClass();
		$item->key           = $key;
		$item->object        = $cart_item;
		$item->product       = $cart_item['data'];
		$item->quantity      = $cart_item['quantity'];
		$item->price         = wc_add_number_precision_deep( $item->product->get_price() * $item->quantity );
		$this->items[ $key ] = $item;
	}

	uasort( $this->items, array( $this, 'sort_by_price' ) );
}