@@ 466-496 (lines=31) @@ | ||
463 | 'coupon' => 'coupon_lines', |
|
464 | ); |
|
465 | ||
466 | foreach ( $lines as $line_type => $line ) { |
|
467 | ||
468 | if ( isset( $data[ $line ] ) && is_array( $data[ $line ] ) ) { |
|
469 | ||
470 | $update_totals = true; |
|
471 | ||
472 | foreach ( $data[ $line ] as $item ) { |
|
473 | ||
474 | // item ID is always required |
|
475 | if ( ! array_key_exists( 'id', $item ) ) { |
|
476 | throw new WC_CLI_Exception( 'woocommerce_invalid_item_id', __( 'Order item ID is required', 'woocommerce' ) ); |
|
477 | } |
|
478 | ||
479 | // create item |
|
480 | if ( is_null( $item['id'] ) ) { |
|
481 | ||
482 | $this->set_item( $order, $line_type, $item, 'create' ); |
|
483 | ||
484 | } elseif ( $this->item_is_null( $item ) ) { |
|
485 | ||
486 | // delete item |
|
487 | wc_delete_order_item( $item['id'] ); |
|
488 | ||
489 | } else { |
|
490 | ||
491 | // update item |
|
492 | $this->set_item( $order, $line_type, $item, 'update' ); |
|
493 | } |
|
494 | } |
|
495 | } |
|
496 | } |
|
497 | ||
498 | // payment method (and payment_complete() if `paid` == true and order needs payment) |
|
499 | if ( isset( $data['payment_details'] ) && is_array( $data['payment_details'] ) ) { |
@@ 605-635 (lines=31) @@ | ||
602 | 'coupon' => 'coupon_lines', |
|
603 | ); |
|
604 | ||
605 | foreach ( $lines as $line_type => $line ) { |
|
606 | ||
607 | if ( isset( $data[ $line ] ) && is_array( $data[ $line ] ) ) { |
|
608 | ||
609 | $update_totals = true; |
|
610 | ||
611 | foreach ( $data[ $line ] as $item ) { |
|
612 | ||
613 | // Item ID is always required. |
|
614 | if ( ! array_key_exists( 'id', $item ) ) { |
|
615 | throw new WC_API_Exception( 'woocommerce_invalid_item_id', __( 'Order item ID is required', 'woocommerce' ), 400 ); |
|
616 | } |
|
617 | ||
618 | // Create item. |
|
619 | if ( is_null( $item['id'] ) ) { |
|
620 | $this->set_item( $order, $line_type, $item, 'create' ); |
|
621 | } elseif ( $this->item_is_null( $item ) ) { |
|
622 | // Delete item. |
|
623 | wc_delete_order_item( $item['id'] ); |
|
624 | } else { |
|
625 | // Update item. |
|
626 | $this->set_item( $order, $line_type, $item, 'update' ); |
|
627 | } |
|
628 | } |
|
629 | } |
|
630 | } |
|
631 | ||
632 | // Payment method (and payment_complete() if `paid` == true and order needs payment). |
|
633 | if ( isset( $data['payment_details'] ) && is_array( $data['payment_details'] ) ) { |
|
634 | ||
635 | // Method ID. |
|
636 | if ( isset( $data['payment_details']['method_id'] ) ) { |
|
637 | update_post_meta( $order->id, '_payment_method', $data['payment_details']['method_id'] ); |
|
638 | } |