2011-08-09 15:16:18 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Order
|
2012-08-08 08:21:27 +00:00
|
|
|
*
|
2014-07-08 18:23:22 +00:00
|
|
|
* @class WC_Order
|
|
|
|
* @version 2.2.0
|
|
|
|
* @package WooCommerce/Classes
|
|
|
|
* @category Class
|
|
|
|
* @author WooThemes
|
2011-08-09 15:16:18 +00:00
|
|
|
*/
|
2014-05-28 19:20:36 +00:00
|
|
|
|
2014-06-13 13:35:53 +00:00
|
|
|
class WC_Order extends WC_Abstract_Order {
|
2014-07-08 18:23:22 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialize the order refund.
|
|
|
|
*
|
|
|
|
* @param int|WC_Order $order
|
|
|
|
*/
|
2014-06-13 13:35:53 +00:00
|
|
|
public function __construct( $order ) {
|
|
|
|
$this->order_type = 'simple';
|
2014-07-08 18:23:22 +00:00
|
|
|
|
2014-06-13 13:35:53 +00:00
|
|
|
parent::__construct( $order );
|
2014-05-28 19:20:36 +00:00
|
|
|
}
|
2014-07-08 18:23:22 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get order refunds
|
|
|
|
*
|
|
|
|
* @since 2.2
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function get_refunds() {
|
|
|
|
global $wpdb;
|
|
|
|
|
|
|
|
$refunds = array();
|
|
|
|
$refund_items = get_posts(
|
|
|
|
array(
|
2014-07-11 11:43:42 +00:00
|
|
|
'post_type' => 'shop_order_refund',
|
2014-07-08 18:23:22 +00:00
|
|
|
'post_parent' => $this->id,
|
|
|
|
'posts_per_page' => -1,
|
2014-07-11 11:43:42 +00:00
|
|
|
'fields' => 'ids'
|
2014-07-08 18:23:22 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
foreach ( $refund_items as $refund_id ) {
|
|
|
|
$refunds[] = new WC_Order_Refund( $refund_id );
|
|
|
|
}
|
|
|
|
|
|
|
|
return $refunds;
|
|
|
|
}
|
2014-07-08 19:59:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get amount already refunded
|
|
|
|
*
|
|
|
|
* @since 2.2
|
|
|
|
* @return int|float
|
|
|
|
*/
|
|
|
|
public function get_total_refunded() {
|
|
|
|
global $wpdb;
|
|
|
|
|
|
|
|
$total = $wpdb->get_var( $wpdb->prepare( "
|
|
|
|
SELECT SUM( postmeta.meta_value )
|
|
|
|
FROM $wpdb->postmeta AS postmeta
|
2014-07-11 11:43:42 +00:00
|
|
|
INNER JOIN $wpdb->posts AS posts ON ( posts.post_type = 'shop_order_refund' AND posts.post_parent = %d )
|
2014-07-08 19:59:38 +00:00
|
|
|
WHERE postmeta.meta_key = '_refund_amount'
|
2014-07-21 02:48:23 +00:00
|
|
|
AND postmeta.post_id = posts.ID
|
2014-07-08 19:59:38 +00:00
|
|
|
", $this->id ) );
|
|
|
|
|
|
|
|
return $total;
|
|
|
|
}
|
2014-07-08 18:23:22 +00:00
|
|
|
}
|