WC_Abstract_Legacy_Order::add_coupon( string|array $code = array(), int $discount, int $discount_tax )

Add coupon code to the order.

Description Description

Parameters Parameters



Default value: array()


(Required) tax amount.


(Required) amount.

Top ↑

Return Return

(int) order item ID

Top ↑

Source Source

File: includes/legacy/abstract-wc-legacy-order.php

	public function add_coupon( $code = array(), $discount = 0, $discount_tax = 0 ) {
		wc_deprecated_function( 'WC_Order::add_coupon', '3.0', 'a new WC_Order_Item_Coupon object and add to order with WC_Order::add_item()' );

		$item = new WC_Order_Item_Coupon();
		$item->set_props( array(
			'code'         => $code,
			'discount'     => $discount,
			'discount_tax' => $discount_tax,
			'order_id'     => $this->get_id(),
		) );
		$this->add_item( $item );
		wc_do_deprecated_action( 'woocommerce_order_add_coupon', array( $this->get_id(), $item->get_id(), $code, $discount, $discount_tax ), '3.0', 'woocommerce_new_order_item action instead.' );
		return $item->get_id();

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.