WC_Discounts::set_items_from_cart()
Normalise cart 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_cart( $cart );
- $cart(WC_Cart) (required)
- Cart object.
Changelog
Since 3.2.0 | Introduced. |
WC_Discounts::set_items_from_cart() WC Discounts::set items from cart code WC 9.7.1
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( (float) $item->product->get_price() * (float) $item->quantity ); $this->items[ $key ] = $item; } uasort( $this->items, array( $this, 'sort_by_price' ) ); }