Code Duplication    Length = 11-16 lines in 4 locations

includes/cli/class-wc-cli-order.php 1 location

@@ 991-1006 (lines=16) @@
988
989
		$item_args = apply_filters( 'woocommerce_cli_order_line_item_args', $item_args, $item, $order, $action );
990
991
		if ( $creating ) {
992
993
			$item_id = $order->add_product( $product, $item_args['qty'], $item_args );
994
995
			if ( ! $item_id ) {
996
				throw new WC_CLI_Exception( 'woocommerce_cannot_create_line_item', __( 'Cannot create line item, try again', 'woocommerce' ) );
997
			}
998
999
		} else {
1000
1001
			$item_id = $order->update_product( $item['id'], $product, $item_args );
1002
1003
			if ( ! $item_id ) {
1004
				throw new WC_CLI_Exception( 'woocommerce_cannot_update_line_item', __( 'Cannot update line item, try again', 'woocommerce' ) );
1005
			}
1006
		}
1007
	}
1008
1009
	/**

includes/api/class-wc-rest-orders-controller.php 1 location

@@ 604-614 (lines=11) @@
601
			$item_args['totals']['subtotal_tax'] = floatval( $item['subtotal_tax'] );
602
		}
603
604
		if ( $creating ) {
605
			$item_id = $order->add_product( $product, $item_args['qty'], $item_args );
606
			if ( ! $item_id ) {
607
				throw new WC_REST_Exception( 'woocommerce_rest_cannot_create_line_item', __( 'Cannot create line item, try again.', 'woocommerce' ), 500 );
608
			}
609
		} else {
610
			$item_id = $order->update_product( $item['id'], $product, $item_args );
611
			if ( ! $item_id ) {
612
				throw new WC_REST_Exception( 'woocommerce_rest_cannot_update_line_item', __( 'Cannot update line item, try again.', 'woocommerce' ), 500 );
613
			}
614
		}
615
	}
616
617
	/**

includes/api/legacy/v2/class-wc-api-orders.php 1 location

@@ 939-954 (lines=16) @@
936
			$item_args['totals']['subtotal_tax'] = floatval( $item['subtotal_tax'] );
937
		}
938
939
		if ( $creating ) {
940
941
			$item_id = $order->add_product( $product, $item_args['qty'], $item_args );
942
943
			if ( ! $item_id ) {
944
				throw new WC_API_Exception( 'woocommerce_cannot_create_line_item', __( 'Cannot create line item, try again', 'woocommerce' ), 500 );
945
			}
946
947
		} else {
948
949
			$item_id = $order->update_product( $item['id'], $product, $item_args );
950
951
			if ( ! $item_id ) {
952
				throw new WC_API_Exception( 'woocommerce_cannot_update_line_item', __( 'Cannot update line item, try again', 'woocommerce' ), 500 );
953
			}
954
		}
955
	}
956
957
	/**

includes/api/legacy/v3/class-wc-api-orders.php 1 location

@@ 984-999 (lines=16) @@
981
982
		$item_args = apply_filters( 'woocommerce_api_order_line_item_args', $item_args, $item, $order, $action );
983
984
		if ( $creating ) {
985
986
			$item_id = $order->add_product( $product, $item_args['qty'], $item_args );
987
988
			if ( ! $item_id ) {
989
				throw new WC_API_Exception( 'woocommerce_cannot_create_line_item', __( 'Cannot create line item, try again', 'woocommerce' ), 500 );
990
			}
991
992
		} else {
993
994
			$item_id = $order->update_product( $item['id'], $product, $item_args );
995
996
			if ( ! $item_id ) {
997
				throw new WC_API_Exception( 'woocommerce_cannot_update_line_item', __( 'Cannot update line item, try again', 'woocommerce' ), 500 );
998
			}
999
		}
1000
	}
1001
1002
	/**