Code Duplication    Length = 13-14 lines in 3 locations

includes/class-wc-order.php 3 locations

@@ 489-501 (lines=13) @@
486
	 * @since 2.2
487
	 * @return string
488
	 */
489
	public function get_total_refunded() {
490
		global $wpdb;
491
492
		$total = $wpdb->get_var( $wpdb->prepare( "
493
			SELECT SUM( postmeta.meta_value )
494
			FROM $wpdb->postmeta AS postmeta
495
			INNER JOIN $wpdb->posts AS posts ON ( posts.post_type = 'shop_order_refund' AND posts.post_parent = %d )
496
			WHERE postmeta.meta_key = '_refund_amount'
497
			AND postmeta.post_id = posts.ID
498
		", $this->get_order_id() ) );
499
500
		return $total;
501
	}
502
503
	/**
504
	 * Get the total tax refunded.
@@ 509-522 (lines=14) @@
506
	 * @since  2.3
507
	 * @return float
508
	 */
509
	public function get_total_tax_refunded() {
510
		global $wpdb;
511
512
		$total = $wpdb->get_var( $wpdb->prepare( "
513
			SELECT SUM( order_itemmeta.meta_value )
514
			FROM {$wpdb->prefix}woocommerce_order_itemmeta AS order_itemmeta
515
			INNER JOIN $wpdb->posts AS posts ON ( posts.post_type = 'shop_order_refund' AND posts.post_parent = %d )
516
			INNER JOIN {$wpdb->prefix}woocommerce_order_items AS order_items ON ( order_items.order_id = posts.ID AND order_items.order_item_type = 'tax' )
517
			WHERE order_itemmeta.order_item_id = order_items.order_item_id
518
			AND order_itemmeta.meta_key IN ('tax_amount', 'shipping_tax_amount')
519
		", $this->get_order_id() ) );
520
521
		return abs( $total );
522
	}
523
524
	/**
525
	 * Get the total shipping refunded.
@@ 530-543 (lines=14) @@
527
	 * @since  2.4
528
	 * @return float
529
	 */
530
	public function get_total_shipping_refunded() {
531
		global $wpdb;
532
533
		$total = $wpdb->get_var( $wpdb->prepare( "
534
			SELECT SUM( order_itemmeta.meta_value )
535
			FROM {$wpdb->prefix}woocommerce_order_itemmeta AS order_itemmeta
536
			INNER JOIN $wpdb->posts AS posts ON ( posts.post_type = 'shop_order_refund' AND posts.post_parent = %d )
537
			INNER JOIN {$wpdb->prefix}woocommerce_order_items AS order_items ON ( order_items.order_id = posts.ID AND order_items.order_item_type = 'shipping' )
538
			WHERE order_itemmeta.order_item_id = order_items.order_item_id
539
			AND order_itemmeta.meta_key IN ('cost')
540
		", $this->get_order_id() ) );
541
542
		return abs( $total );
543
	}
544
545
	/**
546
	 * Gets the count of order items of a certain type that have been refunded.