abstracts
8 years ago
admin
8 years ago
api
8 years ago
cli
8 years ago
customizer
8 years ago
data-stores
8 years ago
emails
8 years ago
export
8 years ago
gateways
8 years ago
import
8 years ago
interfaces
8 years ago
legacy
8 years ago
libraries
8 years ago
log-handlers
8 years ago
payment-tokens
9 years ago
shipping
8 years ago
shortcodes
8 years ago
theme-support
8 years ago
walkers
8 years ago
widgets
8 years ago
class-wc-ajax.php
8 years ago
class-wc-api.php
8 years ago
class-wc-auth.php
8 years ago
class-wc-autoloader.php
8 years ago
class-wc-background-emailer.php
8 years ago
class-wc-background-updater.php
8 years ago
class-wc-breadcrumb.php
8 years ago
class-wc-cache-helper.php
8 years ago
class-wc-cart-fees.php
8 years ago
class-wc-cart-session.php
8 years ago
class-wc-cart-totals.php
8 years ago
class-wc-cart.php
8 years ago
class-wc-checkout.php
8 years ago
class-wc-cli.php
9 years ago
class-wc-comments.php
8 years ago
class-wc-countries.php
8 years ago
class-wc-coupon.php
8 years ago
class-wc-customer-download-log.php
8 years ago
class-wc-customer-download.php
8 years ago
class-wc-customer.php
8 years ago
class-wc-data-exception.php
9 years ago
class-wc-data-store.php
8 years ago
class-wc-datetime.php
8 years ago
class-wc-deprecated-action-hooks.php
8 years ago
class-wc-deprecated-filter-hooks.php
8 years ago
class-wc-discounts.php
8 years ago
class-wc-download-handler.php
8 years ago
class-wc-emails.php
8 years ago
class-wc-embed.php
9 years ago
class-wc-form-handler.php
8 years ago
class-wc-frontend-scripts.php
8 years ago
class-wc-geo-ip.php
9 years ago
class-wc-geolocation.php
8 years ago
class-wc-https.php
9 years ago
class-wc-install.php
8 years ago
class-wc-integrations.php
9 years ago
class-wc-log-levels.php
9 years ago
class-wc-logger.php
8 years ago
class-wc-meta-data.php
8 years ago
class-wc-order-factory.php
8 years ago
class-wc-order-item-coupon.php
8 years ago
class-wc-order-item-fee.php
8 years ago
class-wc-order-item-meta.php
8 years ago
class-wc-order-item-product.php
8 years ago
class-wc-order-item-shipping.php
8 years ago
class-wc-order-item-tax.php
8 years ago
class-wc-order-item.php
8 years ago
class-wc-order-query.php
8 years ago
class-wc-order-refund.php
9 years ago
class-wc-order.php
8 years ago
class-wc-payment-gateways.php
8 years ago
class-wc-payment-tokens.php
9 years ago
class-wc-post-data.php
8 years ago
class-wc-post-types.php
8 years ago
class-wc-product-attribute.php
8 years ago
class-wc-product-download.php
8 years ago
class-wc-product-external.php
8 years ago
class-wc-product-factory.php
9 years ago
class-wc-product-grouped.php
8 years ago
class-wc-product-query.php
8 years ago
class-wc-product-simple.php
8 years ago
class-wc-product-variable.php
8 years ago
class-wc-product-variation.php
8 years ago
class-wc-query.php
8 years ago
class-wc-regenerate-images-request.php
8 years ago
class-wc-regenerate-images.php
8 years ago
class-wc-register-wp-admin-settings.php
9 years ago
class-wc-session-handler.php
8 years ago
class-wc-shipping-rate.php
8 years ago
class-wc-shipping-zone.php
8 years ago
class-wc-shipping-zones.php
8 years ago
class-wc-shipping.php
8 years ago
class-wc-shortcodes.php
8 years ago
class-wc-structured-data.php
8 years ago
class-wc-tax.php
8 years ago
class-wc-template-loader.php
8 years ago
class-wc-tracker.php
8 years ago
class-wc-validation.php
8 years ago
class-wc-webhook.php
8 years ago
class-woocommerce.php
8 years ago
wc-account-functions.php
8 years ago
wc-attribute-functions.php
8 years ago
wc-cart-functions.php
8 years ago
wc-conditional-functions.php
8 years ago
wc-core-functions.php
8 years ago
wc-coupon-functions.php
9 years ago
wc-deprecated-functions.php
8 years ago
wc-formatting-functions.php
8 years ago
wc-notice-functions.php
8 years ago
wc-order-functions.php
8 years ago
wc-order-item-functions.php
9 years ago
wc-page-functions.php
8 years ago
wc-product-functions.php
8 years ago
wc-rest-functions.php
8 years ago
wc-stock-functions.php
8 years ago
wc-template-functions.php
8 years ago
wc-template-hooks.php
8 years ago
wc-term-functions.php
8 years ago
wc-update-functions.php
8 years ago
wc-user-functions.php
8 years ago
wc-webhook-functions.php
8 years ago
wc-widget-functions.php
8 years ago
class-wc-order-refund.php
198 lines
| 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 | * @version 3.0.0 |
| 11 | * @package WooCommerce/Classes |
| 12 | * @category Class |
| 13 | * @author WooThemes |
| 14 | */ |
| 15 | class WC_Order_Refund extends WC_Abstract_Order { |
| 16 | |
| 17 | /** |
| 18 | * Which data store to load. |
| 19 | * |
| 20 | * @var string |
| 21 | */ |
| 22 | protected $data_store_name = 'order-refund'; |
| 23 | |
| 24 | /** |
| 25 | * This is the name of this object type. |
| 26 | * @var string |
| 27 | */ |
| 28 | protected $object_type = 'order_refund'; |
| 29 | |
| 30 | /** |
| 31 | * Stores product data. |
| 32 | * |
| 33 | * @var array |
| 34 | */ |
| 35 | protected $extra_data = array( |
| 36 | 'amount' => '', |
| 37 | 'reason' => '', |
| 38 | 'refunded_by' => 0, |
| 39 | ); |
| 40 | |
| 41 | /** |
| 42 | * Get internal type (post type.) |
| 43 | * @return string |
| 44 | */ |
| 45 | public function get_type() { |
| 46 | return 'shop_order_refund'; |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * Get status - always completed for refunds. |
| 51 | * |
| 52 | * @param string $context |
| 53 | * @return string |
| 54 | */ |
| 55 | public function get_status( $context = 'view' ) { |
| 56 | return 'completed'; |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Get a title for the new post type. |
| 61 | */ |
| 62 | public function get_post_title() { |
| 63 | // @codingStandardsIgnoreStart |
| 64 | return sprintf( __( 'Refund – %s', 'woocommerce' ), strftime( _x( '%b %d, %Y @ %I:%M %p', 'Order date parsed by strftime', 'woocommerce' ) ) ); |
| 65 | // @codingStandardsIgnoreEnd |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * Get refunded amount. |
| 70 | * |
| 71 | * @param string $context |
| 72 | * @return int|float |
| 73 | */ |
| 74 | public function get_amount( $context = 'view' ) { |
| 75 | return $this->get_prop( 'amount', $context ); |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * Get refund reason. |
| 80 | * |
| 81 | * @since 2.2 |
| 82 | * @param string $context |
| 83 | * @return int|float |
| 84 | */ |
| 85 | public function get_reason( $context = 'view' ) { |
| 86 | return $this->get_prop( 'reason', $context ); |
| 87 | } |
| 88 | |
| 89 | /** |
| 90 | * Get ID of user who did the refund. |
| 91 | * |
| 92 | * @since 3.0 |
| 93 | * @param string $context |
| 94 | * @return int |
| 95 | */ |
| 96 | public function get_refunded_by( $context = 'view' ) { |
| 97 | return $this->get_prop( 'refunded_by', $context ); |
| 98 | |
| 99 | } |
| 100 | |
| 101 | /** |
| 102 | * Get formatted refunded amount. |
| 103 | * |
| 104 | * @since 2.4 |
| 105 | * @return string |
| 106 | */ |
| 107 | public function get_formatted_refund_amount() { |
| 108 | return apply_filters( 'woocommerce_formatted_refund_amount', wc_price( $this->get_amount(), array( 'currency' => $this->get_currency() ) ), $this ); |
| 109 | } |
| 110 | |
| 111 | /** |
| 112 | * Set refunded amount. |
| 113 | * |
| 114 | * @param string $value |
| 115 | * @throws WC_Data_Exception |
| 116 | */ |
| 117 | public function set_amount( $value ) { |
| 118 | $this->set_prop( 'amount', wc_format_decimal( $value ) ); |
| 119 | } |
| 120 | |
| 121 | /** |
| 122 | * Set refund reason. |
| 123 | * |
| 124 | * @param string $value |
| 125 | * @throws WC_Data_Exception |
| 126 | */ |
| 127 | public function set_reason( $value ) { |
| 128 | $this->set_prop( 'reason', $value ); |
| 129 | } |
| 130 | |
| 131 | /** |
| 132 | * Set refunded by. |
| 133 | * |
| 134 | * @param int $value |
| 135 | * @throws WC_Data_Exception |
| 136 | */ |
| 137 | public function set_refunded_by( $value ) { |
| 138 | $this->set_prop( 'refunded_by', absint( $value ) ); |
| 139 | } |
| 140 | |
| 141 | /** |
| 142 | * Magic __get method for backwards compatibility. |
| 143 | * |
| 144 | * @param string $key |
| 145 | * @return mixed |
| 146 | */ |
| 147 | public function __get( $key ) { |
| 148 | wc_doing_it_wrong( $key, 'Refund properties should not be accessed directly.', '3.0' ); |
| 149 | /** |
| 150 | * Maps legacy vars to new getters. |
| 151 | */ |
| 152 | if ( 'reason' === $key ) { |
| 153 | return $this->get_reason(); |
| 154 | } elseif ( 'refund_amount' === $key ) { |
| 155 | return $this->get_amount(); |
| 156 | } |
| 157 | return parent::__get( $key ); |
| 158 | } |
| 159 | |
| 160 | /** |
| 161 | * Gets an refund from the database. |
| 162 | * @deprecated 3.0 |
| 163 | * @param int $id (default: 0). |
| 164 | * @return bool |
| 165 | */ |
| 166 | public function get_refund( $id = 0 ) { |
| 167 | wc_deprecated_function( 'get_refund', '3.0', 'read' ); |
| 168 | if ( ! $id ) { |
| 169 | return false; |
| 170 | } |
| 171 | if ( $result = get_post( $id ) ) { |
| 172 | $this->populate( $result ); |
| 173 | return true; |
| 174 | } |
| 175 | return false; |
| 176 | } |
| 177 | |
| 178 | /** |
| 179 | * Get refund amount. |
| 180 | * @deprecated 3.0 |
| 181 | * @return int|float |
| 182 | */ |
| 183 | public function get_refund_amount() { |
| 184 | wc_deprecated_function( 'get_refund_amount', '3.0', 'get_amount' ); |
| 185 | return $this->get_amount(); |
| 186 | } |
| 187 | |
| 188 | /** |
| 189 | * Get refund reason. |
| 190 | * @deprecated 3.0 |
| 191 | * @return int|float |
| 192 | */ |
| 193 | public function get_refund_reason() { |
| 194 | wc_deprecated_function( 'get_refund_reason', '3.0', 'get_reason' ); |
| 195 | return $this->get_reason(); |
| 196 | } |
| 197 | } |
| 198 |