woocommerce/includes/class-wc-order.php

71 lines
1.3 KiB
PHP
Raw Normal View History

2011-08-09 15:16:18 +00:00
<?php
/**
* Order
2012-08-08 08:21:27 +00:00
*
* @class WC_Order
* @version 2.2.0
* @package WooCommerce/Classes
* @category Class
* @author WooThemes
2011-08-09 15:16:18 +00:00
*/
class WC_Order extends WC_Abstract_Order {
/**
* Initialize the order refund.
*
* @param int|WC_Order $order
*/
public function __construct( $order ) {
$this->order_type = 'simple';
parent::__construct( $order );
}
/**
* 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',
'post_parent' => $this->id,
'posts_per_page' => -1,
2014-07-11 11:43:42 +00:00
'fields' => 'ids'
)
);
foreach ( $refund_items as $refund_id ) {
$refunds[] = new WC_Order_Refund( $refund_id );
}
return $refunds;
}
/**
* 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 )
WHERE postmeta.meta_key = '_refund_amount'
GROUP BY posts.ID
", $this->id ) );
return $total;
}
}