Order.php
3 years ago
OrderRefund.php
3 years ago
OrderTraits.php
9 months ago
ThemeUpgrader.php
4 years ago
ThemeUpgraderSkin.php
4 years ago
OrderRefund.php
83 lines
| 1 | <?php |
| 2 | /** |
| 3 | * WC Admin Order Refund |
| 4 | * |
| 5 | * WC Admin Order Refund class that adds some functionality on top of general WooCommerce WC_Order_Refund. |
| 6 | */ |
| 7 | |
| 8 | namespace Automattic\WooCommerce\Admin\Overrides; |
| 9 | |
| 10 | defined( 'ABSPATH' ) || exit; |
| 11 | |
| 12 | use Automattic\WooCommerce\Admin\API\Reports\Customers\DataStore as CustomersDataStore; |
| 13 | |
| 14 | /** |
| 15 | * WC_Order_Refund subclass. |
| 16 | */ |
| 17 | class OrderRefund extends \WC_Order_Refund { |
| 18 | /** |
| 19 | * Order traits. |
| 20 | */ |
| 21 | use OrderTraits; |
| 22 | |
| 23 | /** |
| 24 | * Caches the customer ID. |
| 25 | * |
| 26 | * @var int |
| 27 | */ |
| 28 | public $customer_id = null; |
| 29 | |
| 30 | /** |
| 31 | * Add filter(s) required to hook this class to substitute WC_Order_Refund. |
| 32 | */ |
| 33 | public static function add_filters() { |
| 34 | add_filter( 'woocommerce_order_class', array( __CLASS__, 'order_class_name' ), 10, 3 ); |
| 35 | } |
| 36 | |
| 37 | /** |
| 38 | * Filter function to swap class WC_Order_Refund for this one in cases when it's suitable. |
| 39 | * |
| 40 | * @param string $classname Name of the class to be created. |
| 41 | * @param string $order_type Type of order object to be created. |
| 42 | * @param number $order_id Order id to create. |
| 43 | * |
| 44 | * @return string |
| 45 | */ |
| 46 | public static function order_class_name( $classname, $order_type, $order_id ) { |
| 47 | // @todo - Only substitute class when necessary (during sync). |
| 48 | if ( 'WC_Order_Refund' === $classname ) { |
| 49 | return '\Automattic\WooCommerce\Admin\Overrides\OrderRefund'; |
| 50 | } else { |
| 51 | return $classname; |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * Get the customer ID of the parent order used for reports in the customer lookup table. |
| 57 | * |
| 58 | * @return int|bool Customer ID of parent order, or false if parent order not found. |
| 59 | */ |
| 60 | public function get_report_customer_id() { |
| 61 | if ( is_null( $this->customer_id ) ) { |
| 62 | $parent_order = \wc_get_order( $this->get_parent_id() ); |
| 63 | |
| 64 | if ( ! $parent_order ) { |
| 65 | $this->customer_id = false; |
| 66 | } |
| 67 | |
| 68 | $this->customer_id = CustomersDataStore::get_or_create_customer_from_order( $parent_order ); |
| 69 | } |
| 70 | |
| 71 | return $this->customer_id; |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * Returns null since refunds should not be counted towards returning customer counts. |
| 76 | * |
| 77 | * @return null |
| 78 | */ |
| 79 | public function is_returning_customer() { |
| 80 | return null; |
| 81 | } |
| 82 | } |
| 83 |