WC_Abstract_Legacy_Order::update_coupon()publicWC 1.0

Update coupon for order. Note this does not update order totals.

Метод класса: WC_Abstract_Legacy_Order{}

Хуки из метода

Возвращает

int. updated order item ID

Использование

$WC_Abstract_Legacy_Order = new WC_Abstract_Legacy_Order();
$WC_Abstract_Legacy_Order->update_coupon( $item, $args );
$item(объект|int) (обязательный)
-
$args(массив) (обязательный)
-

Код WC_Abstract_Legacy_Order::update_coupon() WC 8.7.0

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

	// BW compatibility for old args
	if ( isset( $args['discount_amount'] ) ) {
		$args['discount'] = $args['discount_amount'];
	}
	if ( isset( $args['discount_amount_tax'] ) ) {
		$args['discount_tax'] = $args['discount_amount_tax'];
	}

	$item->set_order_id( $this->get_id() );
	$item->set_props( $args );
	$item->save();

	do_action( 'woocommerce_order_update_coupon', $this->get_id(), $item->get_id(), $args );

	return $item->get_id();
}