WordPress at Your Fingertips
function is not described

WC_Discounts::set_items_from_order() public WC 3.2.0

Normalise order 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_order( $order );
$order(WC_Order) (required)
Order object.

Changelog

Since 3.2.0 Introduced.

Code of WC_Discounts::set_items_from_order() WC 5.7.0

public function set_items_from_order( $order ) {
	$this->items     = array();
	$this->discounts = array();

	if ( ! is_a( $order, 'WC_Order' ) ) {
		return;
	}

	$this->object = $order;

	foreach ( $order->get_items() as $order_item ) {
		$item           = new stdClass();
		$item->key      = $order_item->get_id();
		$item->object   = $order_item;
		$item->product  = $order_item->get_product();
		$item->quantity = $order_item->get_quantity();
		$item->price    = wc_add_number_precision_deep( $order_item->get_subtotal() );

		if ( $order->get_prices_include_tax() ) {
			$item->price += wc_add_number_precision_deep( $order_item->get_subtotal_tax() );
		}

		$this->items[ $order_item->get_id() ] = $item;
	}

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