1
|
|
|
<?php |
|
|
|
|
2
|
|
|
if ( ! defined( 'ABSPATH' ) ) { |
3
|
|
|
exit; |
4
|
|
|
} |
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* Legacy Abstract Order |
8
|
|
|
* |
9
|
|
|
* Legacy and deprecated functions are here to keep the WC_Abstract_Order clean. |
10
|
|
|
* This class will be removed in future versions. |
11
|
|
|
* |
12
|
|
|
* @version 2.6.0 |
13
|
|
|
* @package WooCommerce/Abstracts |
14
|
|
|
* @category Abstract Class |
15
|
|
|
* @author WooThemes |
16
|
|
|
*/ |
17
|
|
|
abstract class WC_Abstract_Legacy_Order { |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Update a line item for the order. |
21
|
|
|
* |
22
|
|
|
* Note this does not update order totals. |
23
|
|
|
* |
24
|
|
|
* @since 2.2 |
25
|
|
|
* @param object|int $item order item ID or item object. |
26
|
|
|
* @param WC_Product $product |
27
|
|
|
* @param array $args data to update. |
28
|
|
|
* @return int updated order item ID |
29
|
|
|
*/ |
30
|
|
|
public function update_product( $item, $product, $args ) { |
31
|
|
|
_deprecated_function( 'WC_Order::update_product', '2.6', 'Interact with WC_Order_Item_Product class' ); |
32
|
|
|
if ( is_numeric( $item ) ) { |
33
|
|
|
$item = $this->get_item( $item ); |
|
|
|
|
34
|
|
|
} |
35
|
|
|
if ( ! is_object( $item ) || ! $item->is_type( 'line_item' ) ) { |
36
|
|
|
return false; |
37
|
|
|
} |
38
|
|
|
if ( ! $this->get_id() ) { |
39
|
|
|
$this->save(); // Order must exist |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
// BW compatibility with old args |
43
|
|
View Code Duplication |
if ( isset( $args['totals'] ) ) { |
|
|
|
|
44
|
|
|
foreach ( $args['totals'] as $key => $value ) { |
45
|
|
|
if ( 'tax' === $key ) { |
46
|
|
|
$args['total_tax'] = $value; |
47
|
|
|
} elseif ( 'tax_data' === $key ) { |
48
|
|
|
$args['taxes'] = $value; |
49
|
|
|
} else { |
50
|
|
|
$args[ $key ] = $value; |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
// Handly qty if set |
56
|
|
|
if ( isset( $args['qty'] ) ) { |
57
|
|
View Code Duplication |
if ( $product->backorders_require_notification() && $product->is_on_backorder( $args['qty'] ) ) { |
|
|
|
|
58
|
|
|
$item->add_meta_data( apply_filters( 'woocommerce_backordered_item_meta_name', __( 'Backordered', 'woocommerce' ) ), $args['qty'] - max( 0, $product->get_total_stock() ), true ); |
59
|
|
|
} |
60
|
|
|
$args['subtotal'] = $args['subtotal'] ? $args['subtotal'] : $product->get_price_excluding_tax( $args['qty'] ); |
61
|
|
|
$args['total'] = $args['total'] ? $args['total'] : $product->get_price_excluding_tax( $args['qty'] ); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
$item->set_order_id( $this->get_id() ); |
65
|
|
|
$item->set_all( $args ); |
66
|
|
|
$item->save(); |
67
|
|
|
do_action( 'woocommerce_order_edit_product', $this->get_id(), $item->get_id(), $args, $product ); |
68
|
|
|
|
69
|
|
|
return $item->get_id(); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Update coupon for order. Note this does not update order totals. |
74
|
|
|
* @since 2.2 |
75
|
|
|
* @param object|int $item |
76
|
|
|
* @param array $args |
77
|
|
|
* @return int updated order item ID |
78
|
|
|
*/ |
79
|
|
|
public function update_coupon( $item, $args ) { |
80
|
|
|
_deprecated_function( 'WC_Order::update_coupon', '2.6', 'Interact with WC_Order_Item_Coupon class' ); |
81
|
|
|
if ( is_numeric( $item ) ) { |
82
|
|
|
$item = $this->get_item( $item ); |
|
|
|
|
83
|
|
|
} |
84
|
|
|
if ( ! is_object( $item ) || ! $item->is_type( 'coupon' ) ) { |
85
|
|
|
return false; |
86
|
|
|
} |
87
|
|
|
if ( ! $this->get_id() ) { |
88
|
|
|
$this->save(); // Order must exist |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
// BW compatibility for old args |
92
|
|
|
if ( isset( $args['discount_amount'] ) ) { |
93
|
|
|
$args['discount'] = $args['discount_amount']; |
94
|
|
|
} |
95
|
|
|
if ( isset( $args['discount_amount_tax'] ) ) { |
96
|
|
|
$args['discount_tax'] = $args['discount_amount_tax']; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
$item->set_order_id( $this->get_id() ); |
100
|
|
|
$item->set_all( $args ); |
101
|
|
|
$item->save(); |
102
|
|
|
|
103
|
|
|
do_action( 'woocommerce_order_update_coupon', $this->get_id(), $item->get_id(), $args ); |
104
|
|
|
|
105
|
|
|
return $item->get_id(); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* Update shipping method for order. |
110
|
|
|
* |
111
|
|
|
* Note this does not update the order total. |
112
|
|
|
* |
113
|
|
|
* @since 2.2 |
114
|
|
|
* @param object|int $item |
115
|
|
|
* @param array $args |
116
|
|
|
* @return int updated order item ID |
117
|
|
|
*/ |
118
|
|
|
public function update_shipping( $item, $args ) { |
119
|
|
|
_deprecated_function( 'WC_Order::update_shipping', '2.6', 'Interact with WC_Order_Item_Shipping class' ); |
120
|
|
|
if ( is_numeric( $item ) ) { |
121
|
|
|
$item = $this->get_item( $item ); |
|
|
|
|
122
|
|
|
} |
123
|
|
|
if ( ! is_object( $item ) || ! $item->is_type( 'shipping' ) ) { |
124
|
|
|
return false; |
125
|
|
|
} |
126
|
|
|
if ( ! $this->get_id() ) { |
127
|
|
|
$this->save(); // Order must exist |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
// BW compatibility for old args |
131
|
|
|
if ( isset( $args['cost'] ) ) { |
132
|
|
|
$args['total'] = $args['cost']; |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
$item->set_order_id( $this->get_id() ); |
136
|
|
|
$item->set_all( $args ); |
137
|
|
|
$item->save(); |
138
|
|
|
$this->calculate_shipping(); |
139
|
|
|
|
140
|
|
|
do_action( 'woocommerce_order_update_shipping', $this->get_id(), $item->get_id(), $args ); |
141
|
|
|
|
142
|
|
|
return $item->get_id(); |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* Update fee for order. |
147
|
|
|
* |
148
|
|
|
* Note this does not update order totals. |
149
|
|
|
* |
150
|
|
|
* @since 2.2 |
151
|
|
|
* @param object|int $item |
152
|
|
|
* @param array $args |
153
|
|
|
* @return int updated order item ID |
154
|
|
|
*/ |
155
|
|
View Code Duplication |
public function update_fee( $item, $args ) { |
|
|
|
|
156
|
|
|
_deprecated_function( 'WC_Order::update_fee', '2.6', 'Interact with WC_Order_Item_Fee class' ); |
157
|
|
|
if ( is_numeric( $item ) ) { |
158
|
|
|
$item = $this->get_item( $item ); |
|
|
|
|
159
|
|
|
} |
160
|
|
|
if ( ! is_object( $item ) || ! $item->is_type( 'fee' ) ) { |
161
|
|
|
return false; |
162
|
|
|
} |
163
|
|
|
if ( ! $this->get_id() ) { |
164
|
|
|
$this->save(); // Order must exist |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
$item->set_order_id( $this->get_id() ); |
168
|
|
|
$item->set_all( $args ); |
169
|
|
|
$item->save(); |
170
|
|
|
|
171
|
|
|
do_action( 'woocommerce_order_update_fee', $this->get_id(), $item->get_id(), $args ); |
172
|
|
|
|
173
|
|
|
return $item->get_id(); |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
/** |
177
|
|
|
* Update tax line on order. |
178
|
|
|
* Note this does not update order totals. |
179
|
|
|
* |
180
|
|
|
* @since 2.6 |
181
|
|
|
* @param object|int $item |
182
|
|
|
* @param array $args |
183
|
|
|
* @return int updated order item ID |
184
|
|
|
*/ |
185
|
|
View Code Duplication |
public function update_tax( $item, $args ) { |
|
|
|
|
186
|
|
|
_deprecated_function( 'WC_Order::update_tax', '2.6', 'Interact with WC_Order_Item_Tax class' ); |
187
|
|
|
if ( is_numeric( $item ) ) { |
188
|
|
|
$item = $this->get_item( $item ); |
|
|
|
|
189
|
|
|
} |
190
|
|
|
if ( ! is_object( $item ) || ! $item->is_type( 'tax' ) ) { |
191
|
|
|
return false; |
192
|
|
|
} |
193
|
|
|
if ( ! $this->get_id() ) { |
194
|
|
|
$this->save(); // Order must exist |
195
|
|
|
} |
196
|
|
|
|
197
|
|
|
$item->set_order_id( $this->get_id() ); |
198
|
|
|
$item->set_all( $args ); |
199
|
|
|
$item->save(); |
200
|
|
|
|
201
|
|
|
do_action( 'woocommerce_order_update_tax', $this->get_id(), $item->get_id(), $args ); |
202
|
|
|
|
203
|
|
|
return $item->get_id(); |
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
/** |
207
|
|
|
* Get a product (either product or variation). |
208
|
|
|
* @deprecated Add deprecation notices in future release. Replaced with $item->get_product() |
209
|
|
|
* @param object $item |
210
|
|
|
* @return WC_Product|bool |
211
|
|
|
*/ |
212
|
|
|
public function get_product_from_item( $item ) { |
213
|
|
|
if ( is_callable( array( $item, 'get_product' ) ) ) { |
214
|
|
|
$product = $item->get_product(); |
215
|
|
|
} else { |
216
|
|
|
$product = false; |
217
|
|
|
} |
218
|
|
|
return apply_filters( 'woocommerce_get_product_from_item', $product, $item, $this ); |
219
|
|
|
} |
220
|
|
|
|
221
|
|
|
/** |
222
|
|
|
* Set the customer address. |
223
|
|
|
* @since 2.2.0 |
224
|
|
|
* @param array $address Address data. |
225
|
|
|
* @param string $type billing or shipping. |
226
|
|
|
*/ |
227
|
|
|
public function set_address( $address, $type = 'billing' ) { |
228
|
|
|
foreach ( $address as $key => $value ) { |
229
|
|
|
update_post_meta( $this->get_id(), "_{$type}_" . $key, $value ); |
230
|
|
|
if ( is_callable( array( $this, "set_{$type}_{$key}" ) ) ) { |
231
|
|
|
$this->{"set_{$type}_{$key}"}( $value ); |
232
|
|
|
} |
233
|
|
|
} |
234
|
|
|
} |
235
|
|
|
|
236
|
|
|
/** |
237
|
|
|
* Set an order total. |
238
|
|
|
* @since 2.2.0 |
239
|
|
|
* @param float $amount |
240
|
|
|
* @param string $total_type |
241
|
|
|
* @return bool |
242
|
|
|
*/ |
243
|
|
|
public function legacy_set_total( $amount, $total_type = 'total' ) { |
244
|
|
|
if ( ! in_array( $total_type, array( 'shipping', 'tax', 'shipping_tax', 'total', 'cart_discount', 'cart_discount_tax' ) ) ) { |
245
|
|
|
return false; |
246
|
|
|
} |
247
|
|
|
|
248
|
|
|
switch ( $total_type ) { |
249
|
|
|
case 'total' : |
250
|
|
|
$amount = wc_format_decimal( $amount, wc_get_price_decimals() ); |
251
|
|
|
$this->set_total( $amount ); |
|
|
|
|
252
|
|
|
update_post_meta( $this->get_id(), '_order_total', $amount ); |
253
|
|
|
break; |
254
|
|
|
case 'cart_discount' : |
255
|
|
|
$amount = wc_format_decimal( $amount ); |
256
|
|
|
$this->set_discount_total( $amount ); |
257
|
|
|
update_post_meta( $this->get_id(), '_cart_discount', $amount ); |
258
|
|
|
break; |
259
|
|
|
case 'cart_discount_tax' : |
260
|
|
|
$amount = wc_format_decimal( $amount ); |
261
|
|
|
$this->set_discount_tax( $amount ); |
262
|
|
|
update_post_meta( $this->get_id(), '_cart_discount_tax', $amount ); |
263
|
|
|
break; |
264
|
|
|
case 'shipping' : |
265
|
|
|
$amount = wc_format_decimal( $amount ); |
266
|
|
|
$this->set_shipping_total( $amount ); |
267
|
|
|
update_post_meta( $this->get_id(), '_order_shipping', $amount ); |
268
|
|
|
break; |
269
|
|
|
case 'shipping_tax' : |
270
|
|
|
$amount = wc_format_decimal( $amount ); |
271
|
|
|
$this->set_shipping_tax( $amount ); |
272
|
|
|
update_post_meta( $this->get_id(), '_order_shipping_tax', $amount ); |
273
|
|
|
break; |
274
|
|
|
case 'tax' : |
275
|
|
|
$amount = wc_format_decimal( $amount ); |
276
|
|
|
$this->set_cart_tax( $amount ); |
277
|
|
|
update_post_meta( $this->get_id(), '_order_tax', $amount ); |
278
|
|
|
break; |
279
|
|
|
} |
280
|
|
|
|
281
|
|
|
return true; |
282
|
|
|
} |
283
|
|
|
|
284
|
|
|
/** |
285
|
|
|
* Magic __isset method for backwards compatibility. |
286
|
|
|
* @param string $key |
287
|
|
|
* @return bool |
288
|
|
|
*/ |
289
|
|
|
public function __isset( $key ) { |
290
|
|
|
// Legacy properties which could be accessed directly in the past. |
291
|
|
|
$legacy_props = array( 'completed_date', 'id', 'order_type', 'post', 'status', 'post_status', 'customer_note', 'customer_message', 'user_id', 'customer_user', 'prices_include_tax', 'tax_display_cart', 'display_totals_ex_tax', 'display_cart_ex_tax', 'order_date', 'modified_date', 'cart_discount', 'cart_discount_tax', 'order_shipping', 'order_shipping_tax', 'order_total', 'order_tax', 'billing_first_name', 'billing_last_name', 'billing_company', 'billing_address_1', 'billing_address_2', 'billing_city', 'billing_state', 'billing_postcode', 'billing_country', 'billing_phone', 'billing_email', 'shipping_first_name', 'shipping_last_name', 'shipping_company', 'shipping_address_1', 'shipping_address_2', 'shipping_city', 'shipping_state', 'shipping_postcode', 'shipping_country', 'customer_ip_address', 'customer_user_agent', 'payment_method_title', 'payment_method', 'order_currency' ); |
292
|
|
|
return $this->get_id() ? ( in_array( $key, $legacy_props ) || metadata_exists( 'post', $this->get_id(), '_' . $key ) ) : false; |
293
|
|
|
} |
294
|
|
|
|
295
|
|
|
/** |
296
|
|
|
* Magic __get method for backwards compatibility. |
297
|
|
|
* @param string $key |
298
|
|
|
* @return mixed |
299
|
|
|
*/ |
300
|
|
|
public function __get( $key ) { |
301
|
|
|
_doing_it_wrong( $key, 'Order properties should not be accessed directly.', '2.6' ); |
302
|
|
|
|
303
|
|
|
if ( 'completed_date' === $key ) { |
304
|
|
|
return $this->get_date_completed(); |
|
|
|
|
305
|
|
|
} elseif ( 'paid_date' === $key ) { |
306
|
|
|
return $this->get_date_paid(); |
|
|
|
|
307
|
|
|
} elseif ( 'modified_date' === $key ) { |
308
|
|
|
return $this->get_date_modified(); |
309
|
|
|
} elseif ( 'order_date' === $key ) { |
310
|
|
|
return $this->get_date_created(); |
311
|
|
|
} elseif ( 'id' === $key ) { |
312
|
|
|
return $this->get_id(); |
313
|
|
|
} elseif ( 'post' === $key ) { |
314
|
|
|
return get_post( $this->get_id() ); |
315
|
|
|
} elseif ( 'status' === $key || 'post_status' === $key ) { |
316
|
|
|
return $this->get_status(); |
317
|
|
|
} elseif ( 'customer_message' === $key || 'customer_note' === $key ) { |
318
|
|
|
return $this->get_customer_note(); |
|
|
|
|
319
|
|
|
} elseif ( in_array( $key, array( 'user_id', 'customer_user' ) ) ) { |
320
|
|
|
return $this->get_customer_id(); |
321
|
|
|
} elseif ( 'tax_display_cart' === $key ) { |
322
|
|
|
return get_option( 'woocommerce_tax_display_cart' ); |
323
|
|
|
} elseif ( 'display_totals_ex_tax' === $key ) { |
324
|
|
|
return 'excl' === get_option( 'woocommerce_tax_display_cart' ); |
325
|
|
|
} elseif ( 'display_cart_ex_tax' === $key ) { |
326
|
|
|
return 'excl' === get_option( 'woocommerce_tax_display_cart' ); |
327
|
|
|
} elseif ( 'cart_discount' === $key ) { |
328
|
|
|
return $this->get_discount(); |
|
|
|
|
329
|
|
|
} elseif ( 'cart_discount_tax' === $key ) { |
330
|
|
|
return $this->get_discount_tax(); |
331
|
|
|
} elseif ( 'order_tax' === $key ) { |
332
|
|
|
return $this->get_cart_tax(); |
333
|
|
|
} elseif ( 'order_shipping_tax' === $key ) { |
334
|
|
|
return $this->get_shipping_tax(); |
335
|
|
|
} elseif ( 'order_shipping' === $key ) { |
336
|
|
|
return $this->get_shipping_total(); |
337
|
|
|
} elseif ( 'order_total' === $key ) { |
338
|
|
|
return $this->get_total(); |
|
|
|
|
339
|
|
|
} elseif ( 'order_type' === $key ) { |
340
|
|
|
return $this->get_type(); |
341
|
|
|
} elseif ( 'order_currency' === $key ) { |
342
|
|
|
return $this->get_currency(); |
343
|
|
|
} elseif ( 'order_version' === $key ) { |
344
|
|
|
return $this->get_version(); |
345
|
|
|
} elseif ( is_callable( array( $this, "get_{$key}" ) ) ) { |
346
|
|
|
return $this->{"get_{$key}"}(); |
347
|
|
|
} else { |
348
|
|
|
return get_post_meta( $this->get_id(), '_' . $key, true ); |
349
|
|
|
} |
350
|
|
|
} |
351
|
|
|
|
352
|
|
|
/** |
353
|
|
|
* has_meta function for order items. |
354
|
|
|
* |
355
|
|
|
* @param string $order_item_id |
356
|
|
|
* @return array of meta data. |
357
|
|
|
*/ |
358
|
|
|
public function has_meta( $order_item_id ) { |
359
|
|
|
global $wpdb; |
360
|
|
|
|
361
|
|
|
_deprecated_function( 'has_meta', '2.6', 'WC_Order_item::get_meta_data' ); |
362
|
|
|
|
363
|
|
|
return $wpdb->get_results( $wpdb->prepare( "SELECT meta_key, meta_value, meta_id, order_item_id |
364
|
|
|
FROM {$wpdb->prefix}woocommerce_order_itemmeta WHERE order_item_id = %d |
365
|
|
|
ORDER BY meta_id", absint( $order_item_id ) ), ARRAY_A ); |
366
|
|
|
} |
367
|
|
|
|
368
|
|
|
/** |
369
|
|
|
* Display meta data belonging to an item. |
370
|
|
|
* @param array $item |
371
|
|
|
*/ |
372
|
|
|
public function display_item_meta( $item ) { |
373
|
|
|
_deprecated_function( 'get_item_meta', '2.6', 'wc_display_item_meta' ); |
374
|
|
|
$product = $item->get_product(); |
|
|
|
|
375
|
|
|
$item_meta = new WC_Order_Item_Meta( $item, $product ); |
|
|
|
|
376
|
|
|
$item_meta->display(); |
377
|
|
|
} |
378
|
|
|
|
379
|
|
|
/** |
380
|
|
|
* Display download links for an order item. |
381
|
|
|
* @param array $item |
382
|
|
|
*/ |
383
|
|
|
public function display_item_downloads( $item ) { |
384
|
|
|
$product = $item->get_product(); |
|
|
|
|
385
|
|
|
|
386
|
|
|
if ( $product && $product->exists() && $product->is_downloadable() && $this->is_download_permitted() ) { |
|
|
|
|
387
|
|
|
$download_files = $this->get_item_downloads( $item ); |
388
|
|
|
$i = 0; |
389
|
|
|
$links = array(); |
390
|
|
|
|
391
|
|
|
foreach ( $download_files as $download_id => $file ) { |
392
|
|
|
$i++; |
393
|
|
|
$prefix = count( $download_files ) > 1 ? sprintf( __( 'Download %d', 'woocommerce' ), $i ) : __( 'Download', 'woocommerce' ); |
394
|
|
|
$links[] = '<small class="download-url">' . $prefix . ': <a href="' . esc_url( $file['download_url'] ) . '" target="_blank">' . esc_html( $file['name'] ) . '</a></small>' . "\n"; |
395
|
|
|
} |
396
|
|
|
|
397
|
|
|
echo '<br/>' . implode( '<br/>', $links ); |
398
|
|
|
} |
399
|
|
|
} |
400
|
|
|
|
401
|
|
|
/** |
402
|
|
|
* Get the Download URL. |
403
|
|
|
* |
404
|
|
|
* @param int $product_id |
405
|
|
|
* @param int $download_id |
406
|
|
|
* @return string |
407
|
|
|
*/ |
408
|
|
|
public function get_download_url( $product_id, $download_id ) { |
409
|
|
|
return add_query_arg( array( |
410
|
|
|
'download_file' => $product_id, |
411
|
|
|
'order' => $this->get_order_key(), |
|
|
|
|
412
|
|
|
'email' => urlencode( $this->get_billing_email() ), |
|
|
|
|
413
|
|
|
'key' => $download_id, |
414
|
|
|
), trailingslashit( home_url() ) ); |
415
|
|
|
} |
416
|
|
|
|
417
|
|
|
/** |
418
|
|
|
* Get the downloadable files for an item in this order. |
419
|
|
|
* |
420
|
|
|
* @param array $item |
421
|
|
|
* @return array |
422
|
|
|
*/ |
423
|
|
|
public function get_item_downloads( $item ) { |
424
|
|
|
global $wpdb; |
425
|
|
|
|
426
|
|
|
$product = $item->get_product(); |
|
|
|
|
427
|
|
|
|
428
|
|
|
if ( ! $product ) { |
429
|
|
|
/** |
430
|
|
|
* $product can be `false`. Example: checking an old order, when a product or variation has been deleted. |
431
|
|
|
* @see \WC_Product_Factory::get_product |
432
|
|
|
*/ |
433
|
|
|
return array(); |
434
|
|
|
} |
435
|
|
|
$download_ids = $wpdb->get_col( $wpdb->prepare(" |
436
|
|
|
SELECT download_id |
437
|
|
|
FROM {$wpdb->prefix}woocommerce_downloadable_product_permissions |
438
|
|
|
WHERE user_email = %s |
439
|
|
|
AND order_key = %s |
440
|
|
|
AND product_id = %d |
441
|
|
|
ORDER BY permission_id |
442
|
|
|
", $this->get_billing_email(), $this->get_order_key(), $product_id ) ); |
|
|
|
|
443
|
|
|
|
444
|
|
|
$files = array(); |
445
|
|
|
|
446
|
|
|
foreach ( $download_ids as $download_id ) { |
447
|
|
|
|
448
|
|
|
if ( $product->has_file( $download_id ) ) { |
449
|
|
|
$files[ $download_id ] = $product->get_file( $download_id ); |
450
|
|
|
$files[ $download_id ]['download_url'] = $this->get_download_url( $product_id, $download_id ); |
451
|
|
|
} |
452
|
|
|
} |
453
|
|
|
|
454
|
|
|
return apply_filters( 'woocommerce_get_item_downloads', $files, $item, $this ); |
455
|
|
|
} |
456
|
|
|
|
457
|
|
|
/** |
458
|
|
|
* Gets shipping total. Alias of WC_Order::get_shipping_total(). |
459
|
|
|
* @deprecated 2.6.0 since this is an alias only. |
460
|
|
|
* @return float |
461
|
|
|
*/ |
462
|
|
|
public function get_total_shipping() { |
463
|
|
|
return $this->get_shipping_total(); |
464
|
|
|
} |
465
|
|
|
|
466
|
|
|
/** |
467
|
|
|
* Get order item meta. |
468
|
|
|
* @deprecated 2.6.0 |
469
|
|
|
* @param mixed $order_item_id |
470
|
|
|
* @param string $key (default: '') |
471
|
|
|
* @param bool $single (default: false) |
472
|
|
|
* @return array|string |
473
|
|
|
*/ |
474
|
|
|
public function get_item_meta( $order_item_id, $key = '', $single = false ) { |
475
|
|
|
_deprecated_function( 'get_item_meta', '2.6', 'wc_get_order_item_meta' ); |
476
|
|
|
return get_metadata( 'order_item', $order_item_id, $key, $single ); |
477
|
|
|
} |
478
|
|
|
|
479
|
|
|
/** |
480
|
|
|
* Get all item meta data in array format in the order it was saved. Does not group meta by key like get_item_meta(). |
481
|
|
|
* |
482
|
|
|
* @param mixed $order_item_id |
483
|
|
|
* @return array of objects |
484
|
|
|
*/ |
485
|
|
|
public function get_item_meta_array( $order_item_id ) { |
486
|
|
|
_deprecated_function( 'get_item_meta_array', '2.6', 'WC_Order_Item::get_meta_data()' ); |
487
|
|
|
$item = $this->get_item( $order_item_id ); |
|
|
|
|
488
|
|
|
return $item->get_meta_data(); |
489
|
|
|
} |
490
|
|
|
|
491
|
|
|
/** |
492
|
|
|
* Expand item meta into the $item array. |
493
|
|
|
* @deprecated 2.6.0 Item meta no longer expanded due to new order item |
494
|
|
|
* classes. This function now does nothing to avoid data breakage. |
495
|
|
|
* @since 2.4.0 |
496
|
|
|
* @param array $item before expansion. |
497
|
|
|
* @return array |
498
|
|
|
*/ |
499
|
|
|
public function expand_item_meta( $item ) { |
500
|
|
|
_deprecated_function( 'expand_item_meta', '2.6', '' ); |
501
|
|
|
return $item; |
502
|
|
|
} |
503
|
|
|
|
504
|
|
|
/** |
505
|
|
|
* Load the order object. Called from the constructor. |
506
|
|
|
* @deprecated 2.6.0 Logic moved to constructor |
507
|
|
|
* @param int|object|WC_Order $order Order to init. |
508
|
|
|
*/ |
509
|
|
View Code Duplication |
protected function init( $order ) { |
|
|
|
|
510
|
|
|
_deprecated_function( 'init', '2.6', 'Logic moved to constructor' ); |
511
|
|
|
if ( is_numeric( $order ) ) { |
512
|
|
|
$this->read( $order ); |
513
|
|
|
} elseif ( $order instanceof WC_Order ) { |
514
|
|
|
$this->read( absint( $order->get_id() ) ); |
515
|
|
|
} elseif ( isset( $order->ID ) ) { |
516
|
|
|
$this->read( absint( $order->ID ) ); |
517
|
|
|
} |
518
|
|
|
} |
519
|
|
|
|
520
|
|
|
/** |
521
|
|
|
* Gets an order from the database. |
522
|
|
|
* @deprecated 2.6 |
523
|
|
|
* @param int $id (default: 0). |
524
|
|
|
* @return bool |
525
|
|
|
*/ |
526
|
|
View Code Duplication |
public function get_order( $id = 0 ) { |
|
|
|
|
527
|
|
|
_deprecated_function( 'get_order', '2.6', 'read' ); |
528
|
|
|
if ( ! $id ) { |
529
|
|
|
return false; |
530
|
|
|
} |
531
|
|
|
if ( $result = get_post( $id ) ) { |
532
|
|
|
$this->populate( $result ); |
|
|
|
|
533
|
|
|
return true; |
534
|
|
|
} |
535
|
|
|
return false; |
536
|
|
|
} |
537
|
|
|
|
538
|
|
|
/** |
539
|
|
|
* Populates an order from the loaded post data. |
540
|
|
|
* @deprecated 2.6 |
541
|
|
|
* @param mixed $result |
542
|
|
|
*/ |
543
|
|
|
public function populate( $result ) { |
544
|
|
|
_deprecated_function( 'populate', '2.6', 'read' ); |
545
|
|
|
$this->read( $result->ID ); |
546
|
|
|
} |
547
|
|
|
|
548
|
|
|
/** |
549
|
|
|
* Cancel the order and restore the cart (before payment). |
550
|
|
|
* @deprecated 2.6.0 Moved to event handler. |
551
|
|
|
* @param string $note (default: '') Optional note to add. |
552
|
|
|
*/ |
553
|
|
|
public function cancel_order( $note = '' ) { |
554
|
|
|
_deprecated_function( 'cancel_order', '2.6', 'update_status' ); |
555
|
|
|
WC()->session->set( 'order_awaiting_payment', false ); |
556
|
|
|
$this->update_status( 'cancelled', $note ); |
|
|
|
|
557
|
|
|
} |
558
|
|
|
|
559
|
|
|
/** |
560
|
|
|
* Record sales. |
561
|
|
|
* @deprecated 2.6.0 |
562
|
|
|
*/ |
563
|
|
|
public function record_product_sales() { |
564
|
|
|
_deprecated_function( 'record_product_sales', '2.6', 'wc_update_total_sales_counts' ); |
565
|
|
|
wc_update_total_sales_counts( $this->get_id() ); |
566
|
|
|
} |
567
|
|
|
|
568
|
|
|
/** |
569
|
|
|
* Increase applied coupon counts. |
570
|
|
|
* @deprecated 2.6.0 |
571
|
|
|
*/ |
572
|
|
|
public function increase_coupon_usage_counts() { |
573
|
|
|
_deprecated_function( 'increase_coupon_usage_counts', '2.6', 'wc_update_coupon_usage_counts' ); |
574
|
|
|
wc_update_coupon_usage_counts( $this->get_id() ); |
575
|
|
|
} |
576
|
|
|
|
577
|
|
|
/** |
578
|
|
|
* Decrease applied coupon counts. |
579
|
|
|
* @deprecated 2.6.0 |
580
|
|
|
*/ |
581
|
|
|
public function decrease_coupon_usage_counts() { |
582
|
|
|
_deprecated_function( 'decrease_coupon_usage_counts', '2.6', 'wc_update_coupon_usage_counts' ); |
583
|
|
|
wc_update_coupon_usage_counts( $this->get_id() ); |
584
|
|
|
} |
585
|
|
|
|
586
|
|
|
/** |
587
|
|
|
* Reduce stock levels for all line items in the order. |
588
|
|
|
* @deprecated 2.6.0 |
589
|
|
|
*/ |
590
|
|
|
public function reduce_order_stock() { |
591
|
|
|
_deprecated_function( 'reduce_order_stock', '2.6', 'wc_reduce_stock_levels' ); |
592
|
|
|
wc_reduce_stock_levels( $this->get_id() ); |
593
|
|
|
} |
594
|
|
|
|
595
|
|
|
/** |
596
|
|
|
* Send the stock notifications. |
597
|
|
|
* @deprecated 2.6.0 No longer needs to be called directly. |
598
|
|
|
*/ |
599
|
|
|
public function send_stock_notifications( $product, $new_stock, $qty_ordered ) { |
|
|
|
|
600
|
|
|
_deprecated_function( 'send_stock_notifications', '2.6' ); |
601
|
|
|
} |
602
|
|
|
|
603
|
|
|
/** |
604
|
|
|
* Output items for display in html emails. |
605
|
|
|
* @deprecated 2.6.0 Moved to template functions. |
606
|
|
|
* @param array $args Items args. |
607
|
|
|
* @return string |
608
|
|
|
*/ |
609
|
|
|
public function email_order_items_table( $args = array() ) { |
610
|
|
|
return wc_get_email_order_items( $this, $args ); |
|
|
|
|
611
|
|
|
} |
612
|
|
|
} |
613
|
|
|
|
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.