WC_Abstract_Order::remove_coupon( string $code )
Remove a coupon from the order and recalculate totals.
Description Description
Coupons affect line item totals, but there is no relationship between coupon and line total, so to remove a coupon we need to work from the line subtotal (price before discount) and re-apply all coupons in this order.
Manual discounts are not affected; those are separate and do not affect stored line totals.
Parameters Parameters
- $code
-
(Required) Coupon code.
Return Return
(void)
Source Source
File: includes/abstracts/abstract-wc-order.php
1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 | public function remove_coupon( $code ) { $coupons = $this ->get_items( 'coupon' ); // Remove the coupon line. foreach ( $coupons as $item_id => $coupon ) { if ( $coupon ->get_code() === $code ) { $this ->remove_item( $item_id ); $coupon_object = new WC_Coupon( $code ); $coupon_object ->decrease_usage_count( $this ->get_user_id() ); $this ->recalculate_coupons(); break ; } } } |
Changelog Changelog
Version | Description |
---|---|
3.2.0 | Introduced. |