WC_Abstract_Legacy_Order::update_product()publicWC 1.0

Update a line item for the order.

Note this does not update order totals.

Method of the class: WC_Abstract_Legacy_Order{}

Return

Int. updated order item ID

Usage

$WC_Abstract_Legacy_Order = new WC_Abstract_Legacy_Order();
$WC_Abstract_Legacy_Order->update_product( $item, $product, $args );
$item(object|int) (required)
order item ID or item object.
$product(WC_Product) (required)
-
$args(array) (required)
data to update.

WC_Abstract_Legacy_Order::update_product() code WC 8.7.0

public function update_product( $item, $product, $args ) {
	wc_deprecated_function( 'WC_Order::update_product', '3.0', 'an interaction with the WC_Order_Item_Product class' );
	if ( is_numeric( $item ) ) {
		$item = $this->get_item( $item );
	}
	if ( ! is_object( $item ) || ! $item->is_type( 'line_item' ) ) {
		return false;
	}
	if ( ! $this->get_id() ) {
		$this->save(); // Order must exist
	}

	// BW compatibility with old args
	if ( isset( $args['totals'] ) ) {
		foreach ( $args['totals'] as $key => $value ) {
			if ( 'tax' === $key ) {
				$args['total_tax'] = $value;
			} elseif ( 'tax_data' === $key ) {
				$args['taxes'] = $value;
			} else {
				$args[ $key ] = $value;
			}
		}
	}

	// Handle qty if set.
	if ( isset( $args['qty'] ) ) {
		if ( $product->backorders_require_notification() && $product->is_on_backorder( $args['qty'] ) ) {
			$item->add_meta_data( apply_filters( 'woocommerce_backordered_item_meta_name', __( 'Backordered', 'woocommerce' ), $item ), $args['qty'] - max( 0, $product->get_stock_quantity() ), true );
		}
		$args['subtotal'] = $args['subtotal'] ? $args['subtotal'] : wc_get_price_excluding_tax( $product, array( 'qty' => $args['qty'] ) );
		$args['total']	= $args['total'] ? $args['total'] : wc_get_price_excluding_tax( $product, array( 'qty' => $args['qty'] ) );
	}

	$item->set_order_id( $this->get_id() );
	$item->set_props( $args );
	$item->save();
	do_action( 'woocommerce_order_edit_product', $this->get_id(), $item->get_id(), $args, $product );

	return $item->get_id();
}