Fixed allow to remove coupons when using line item ID.

This commit is contained in:
Claudio Sanches 2018-09-11 17:18:59 -03:00
parent 2b7e5121f2
commit fda3f6890c
1 changed files with 9 additions and 2 deletions

View File

@ -72,8 +72,15 @@ class WC_REST_Orders_Controller extends WC_REST_Orders_V2_Controller {
foreach ( $value as $item ) {
if ( is_array( $item ) ) {
if ( $this->item_is_null( $item ) || ( isset( $item['quantity'] ) && 0 === $item['quantity'] ) ) {
if ( ! empty( $item['id'] ) ) {
$order->remove_item( $item['id'] );
if ( ! empty( $item['id'] ) && empty( $item['code'] ) ) {
$coupons = $order->get_items( 'coupon' );
foreach ( $coupons as $item_id => $coupon ) {
if ( $item_id === $item['id'] ) {
$order->remove_coupon( $coupon->get_code() );
break;
}
}
} elseif ( ! empty( $item['code'] ) ) {
$order->remove_coupon( wc_clean( $item['code'] ) );
}