1
|
|
|
<?php |
|
|
|
|
2
|
|
|
if ( ! defined( 'ABSPATH' ) ) { |
3
|
|
|
exit; |
4
|
|
|
} |
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* Order refund. Refunds are based on orders (essentially negative orders) and |
8
|
|
|
* contain much of the same data. |
9
|
|
|
* |
10
|
|
|
* @class WC_Order_Refund |
11
|
|
|
* @version 2.6.0 |
12
|
|
|
* @package WooCommerce/Classes |
13
|
|
|
* @category Class |
14
|
|
|
* @author WooThemes |
15
|
|
|
*/ |
16
|
|
|
class WC_Order_Refund extends WC_Abstract_Order { |
17
|
|
|
|
18
|
|
|
/** @public string Order type */ |
19
|
|
|
public $order_type = 'refund'; |
20
|
|
|
|
21
|
|
|
/** @var string Date */ |
22
|
|
|
public $date; |
23
|
|
|
|
24
|
|
|
/** @var string Refund reason */ |
25
|
|
|
public $reason; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Data array, with defaults. |
29
|
|
|
* |
30
|
|
|
* @todo when migrating to custom tables, these will be columns |
31
|
|
|
* @since 2.6.0 |
32
|
|
|
* @var array |
33
|
|
|
*/ |
34
|
|
|
protected $_refund_data = array( |
35
|
|
|
'refund_amount' => '', |
36
|
|
|
'refund_reason' => '', |
37
|
|
|
); |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Get the refund if ID is passed, otherwise the refund is new and empty. |
41
|
|
|
* @param int|object|WC_Order_Refund $refund Refund to init. |
42
|
|
|
*/ |
43
|
|
View Code Duplication |
public function __construct( $refund = 0 ) { |
|
|
|
|
44
|
|
|
if ( is_numeric( $refund ) ) { |
45
|
|
|
$this->read( $refund ); |
46
|
|
|
} elseif ( $order instanceof WC_Order_Refund ) { |
47
|
|
|
$this->read( absint( $refund->get_id() ) ); |
48
|
|
|
} elseif ( ! empty( $refund->ID ) ) { |
49
|
|
|
$this->read( absint( $refund->ID ) ); |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Get refunded amount. |
55
|
|
|
* |
56
|
|
|
* @since 2.2 |
57
|
|
|
* @return int|float |
58
|
|
|
*/ |
59
|
|
|
public function get_refund_amount() { |
60
|
|
|
return apply_filters( 'woocommerce_refund_amount', (double) $this->refund_amount, $this ); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Get formatted refunded amount. |
65
|
|
|
* |
66
|
|
|
* @since 2.4 |
67
|
|
|
* @return string |
68
|
|
|
*/ |
69
|
|
|
public function get_formatted_refund_amount() { |
70
|
|
|
return apply_filters( 'woocommerce_formatted_refund_amount', wc_price( $this->refund_amount, array('currency' => $this->get_order_currency()) ), $this ); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Get refunded amount. |
75
|
|
|
* |
76
|
|
|
* @since 2.2 |
77
|
|
|
* @return int|float |
78
|
|
|
*/ |
79
|
|
|
public function get_refund_reason() { |
80
|
|
|
return apply_filters( 'woocommerce_refund_reason', $this->reason, $this ); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Gets an refund from the database. |
85
|
|
|
* @deprecated 2.6 |
86
|
|
|
* @param int $id (default: 0). |
87
|
|
|
* @return bool |
88
|
|
|
*/ |
89
|
|
View Code Duplication |
public function get_refund( $id = 0 ) { |
|
|
|
|
90
|
|
|
_deprecated_function( 'get_refund', '2.6', 'read' ); |
91
|
|
|
if ( ! $id ) { |
92
|
|
|
return false; |
93
|
|
|
} |
94
|
|
|
if ( $result = get_post( $id ) ) { |
95
|
|
|
$this->populate( $result ); |
|
|
|
|
96
|
|
|
return true; |
97
|
|
|
} |
98
|
|
|
return false; |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.