Code Duplication    Length = 28-30 lines in 2 locations

includes/api/legacy/v1/class-wc-api-customers.php 1 location

@@ 259-286 (lines=28) @@
256
	 * @param string $fields fields to include in response
257
	 * @return array
258
	 */
259
	public function get_customer_orders( $id, $fields = null ) {
260
		global $wpdb;
261
262
		$id = $this->validate_request( $id, 'customer', 'read' );
263
264
		if ( is_wp_error( $id ) )
265
			return $id;
266
267
		$order_ids = $wpdb->get_col( $wpdb->prepare( "SELECT id
268
						FROM $wpdb->posts AS posts
269
						LEFT JOIN {$wpdb->postmeta} AS meta on posts.ID = meta.post_id
270
						WHERE meta.meta_key = '_customer_user'
271
						AND   meta.meta_value = '%s'
272
						AND   posts.post_type = 'shop_order'
273
						AND   posts.post_status = IN ( '" . implode( "','", array_keys( wc_get_order_statuses() ) ) . "' )
274
					", $id ) );
275
276
		if ( empty( $order_ids ) )
277
			return array( 'orders' => array() );
278
279
		$orders = array();
280
281
		foreach ( $order_ids as $order_id ) {
282
			$orders[] = current( WC()->api->WC_API_Orders->get_order( $order_id, $fields ) );
283
		}
284
285
		return array( 'orders' => apply_filters( 'woocommerce_api_customer_orders_response', $orders, $id, $fields, $order_ids, $this->server ) );
286
	}
287
288
	/**
289
	 * Helper method to get customer user objects

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

@@ 466-495 (lines=30) @@
463
	 * @param string $fields fields to include in response
464
	 * @return array
465
	 */
466
	public function get_customer_orders( $id, $fields = null ) {
467
		global $wpdb;
468
469
		$id = $this->validate_request( $id, 'customer', 'read' );
470
471
		if ( is_wp_error( $id ) ) {
472
			return $id;
473
		}
474
475
		$order_ids = $wpdb->get_col( $wpdb->prepare( "SELECT id
476
						FROM $wpdb->posts AS posts
477
						LEFT JOIN {$wpdb->postmeta} AS meta on posts.ID = meta.post_id
478
						WHERE meta.meta_key = '_customer_user'
479
						AND   meta.meta_value = '%s'
480
						AND   posts.post_type = 'shop_order'
481
						AND   posts.post_status IN ( '" . implode( "','", array_keys( wc_get_order_statuses() ) ) . "' )
482
					", $id ) );
483
484
		if ( empty( $order_ids ) ) {
485
			return array( 'orders' => array() );
486
		}
487
488
		$orders = array();
489
490
		foreach ( $order_ids as $order_id ) {
491
			$orders[] = current( WC()->api->WC_API_Orders->get_order( $order_id, $fields ) );
492
		}
493
494
		return array( 'orders' => apply_filters( 'woocommerce_api_customer_orders_response', $orders, $id, $fields, $order_ids, $this->server ) );
495
	}
496
497
	/**
498
	 * Get the available downloads for a customer