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
- $code
-
(Optional)
Default value: array()
- $discount
-
(Required) tax amount.
- $discount_tax
-
(Required) amount.
Return Return
(int) order item ID
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(), ) ); $item->save(); $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(); }