created initial methods for WC_Order_Refund class
This commit is contained in:
parent
9d4ef6fd9b
commit
03d9ab0c81
|
@ -2,7 +2,7 @@
|
|||
/**
|
||||
* Order refund
|
||||
*
|
||||
* @class WC_Order
|
||||
* @class WC_Order_Refund
|
||||
* @version 2.2.0
|
||||
* @package WooCommerce/Classes
|
||||
* @category Class
|
||||
|
@ -14,11 +14,79 @@ class WC_Order_Refund extends WC_Abstract_Order {
|
|||
/**
|
||||
* Initialize the order refund.
|
||||
*
|
||||
* @param int|WC_Order $order
|
||||
* @param int|WC_Order_Refund $refund
|
||||
*/
|
||||
public function __construct( $order ) {
|
||||
public function __construct( $refund ) {
|
||||
$this->order_type = 'refund';
|
||||
|
||||
parent::__construct( $order );
|
||||
if ( is_numeric( $refund ) ) {
|
||||
$this->id = absint( $refund );
|
||||
$this->post = get_post( $refund );
|
||||
$this->get_refund( $this->id );
|
||||
} elseif ( $refund instanceof WC_Order_Refund ) {
|
||||
$this->id = absint( $refund->id );
|
||||
$this->post = $refund->post;
|
||||
$this->get_refund( $this->id );
|
||||
} elseif ( $refund instanceof WC_Order_Refund || isset( $refund->ID ) ) {
|
||||
$this->id = absint( $refund->ID );
|
||||
$this->post = $refund;
|
||||
$this->get_refund( $this->id );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an refund from the database
|
||||
*
|
||||
* @since 2.2
|
||||
* @param int $id
|
||||
* @return bool
|
||||
*/
|
||||
public function get_refund( $id = 0 ) {
|
||||
if ( ! $id ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( $result = get_post( $id ) ) {
|
||||
$this->populate( $result );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Populates an refund from the loaded post data
|
||||
*
|
||||
* @since 2.2
|
||||
* @param mixed $result
|
||||
* @return void
|
||||
*/
|
||||
public function populate( $result ) {
|
||||
// Standard post data
|
||||
$this->id = $result->ID;
|
||||
$this->date = $result->post_date;
|
||||
$this->modified_date = $result->post_modified;
|
||||
$this->reason = $result->post_excerpt;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get refunded amount
|
||||
*
|
||||
* @since 2.2
|
||||
* @return int|float
|
||||
*/
|
||||
public function get_refund_amount() {
|
||||
return apply_filters( 'woocommerce_refund_amount', (double) $this->refund_amount, $this );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get refunded amount
|
||||
*
|
||||
* @since 2.2
|
||||
* @return int|float
|
||||
*/
|
||||
public function get_refund_reason() {
|
||||
return apply_filters( 'woocommerce_refund_reason', $this->reason, $this );
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue