WC_Discounts::set_items_from_order()publicWC 3.2.0

Normalise order items which will be discounted.

Method of the class: WC_Discounts{}

No Hooks.

Return

null. Nothing (null).

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.

WC_Discounts::set_items_from_order() code WC 9.3.3

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' ) );
}