1
|
|
|
<?php |
2
|
|
|
if ( ! defined( 'ABSPATH' ) ) { |
3
|
|
|
exit; |
4
|
|
|
} |
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* Legacy Cart. |
8
|
|
|
* |
9
|
|
|
* Legacy and deprecated functions are here to keep the WC_Cart class clean. |
10
|
|
|
* This class will be removed in future versions. |
11
|
|
|
* |
12
|
|
|
* @class WC_Legacy_Cart |
13
|
|
|
* @version 2.7.0 |
14
|
|
|
* @package WooCommerce/Classes |
15
|
|
|
* @category Class |
16
|
|
|
* @author WooThemes |
17
|
|
|
*/ |
18
|
|
|
abstract class WC_Legacy_Cart { |
19
|
|
|
/** |
20
|
|
|
* Handle unset props. |
21
|
|
|
* @param string $key |
22
|
|
|
* @return mixed |
23
|
|
|
*/ |
24
|
|
|
public function __get( $key ) { |
25
|
|
|
_doing_it_wrong( $key, 'Cart properties should not be accessed directly.', '2.7' ); |
26
|
|
|
|
27
|
|
|
switch ( $key ) { |
28
|
|
|
case 'cart_session_data' : |
29
|
|
|
return array( |
30
|
|
|
'cart_contents_total' => $this->cart_contents_total, |
31
|
|
|
'total' => $this->total, |
32
|
|
|
'subtotal' => $this->subtotal, |
33
|
|
|
'subtotal_ex_tax' => $this->subtotal_ex_tax, |
34
|
|
|
'tax_total' => $this->tax_total, |
35
|
|
|
'taxes' => $this->taxes, |
36
|
|
|
'shipping_taxes' => $this->shipping_taxes, |
37
|
|
|
'discount_cart' => $this->discount_cart, |
38
|
|
|
'discount_cart_tax' => $this->discount_cart_tax, |
39
|
|
|
'shipping_total' => $this->shipping_total, |
40
|
|
|
'shipping_tax_total' => $this->shipping_tax_total, |
41
|
|
|
'coupon_discount_amounts' => $this->coupon_discount_amounts, |
42
|
|
|
'coupon_discount_tax_amounts' => $this->coupon_discount_tax_amounts, |
43
|
|
|
'fee_total' => $this->fee_total, |
44
|
|
|
'fees' => $this->fees, |
45
|
|
|
); |
46
|
|
|
case 'subtotal' : |
47
|
|
|
return $this->get_subtotal( true ); |
|
|
|
|
48
|
|
|
case 'subtotal_ex_tax' : |
49
|
|
|
return $this->get_subtotal( false ); |
|
|
|
|
50
|
|
|
case 'taxes' : |
51
|
|
|
return $this->get_taxes(); |
|
|
|
|
52
|
|
|
case 'discount_cart' : |
53
|
|
|
return $this->get_cart_discount_total(); |
|
|
|
|
54
|
|
|
case 'discount_cart_tax' : |
55
|
|
|
return $this->get_cart_discount_tax_total(); |
|
|
|
|
56
|
|
|
case 'cart_contents' : |
57
|
|
|
return $this->get_cart(); |
|
|
|
|
58
|
|
|
case 'removed_cart_contents' : |
59
|
|
|
return $this->items->get_removed_items(); |
60
|
|
|
case 'tax_total' : |
61
|
|
|
return $this->get_tax_total(); |
|
|
|
|
62
|
|
|
case 'shipping_tax_total': |
63
|
|
|
return $this->get_shipping_tax_total(); |
|
|
|
|
64
|
|
|
case 'prices_include_tax' : |
65
|
|
|
return wc_prices_include_tax(); |
66
|
|
|
case 'round_at_subtotal' : |
67
|
|
|
return 'yes' === get_option( 'woocommerce_tax_round_at_subtotal' ); |
68
|
|
|
case 'tax_display_cart' : |
69
|
|
|
return get_option( 'woocommerce_tax_display_cart' ); |
70
|
|
|
case 'dp' : |
71
|
|
|
return wc_get_price_decimals(); |
72
|
|
|
case 'display_totals_ex_tax' : |
73
|
|
|
case 'display_cart_ex_tax' : |
74
|
|
|
return $this->tax_display_cart === 'excl'; |
75
|
|
|
case 'cart_contents_weight' : |
76
|
|
|
return $this->get_cart_contents_weight(); |
|
|
|
|
77
|
|
|
case 'cart_contents_count' : |
78
|
|
|
return $this->get_cart_contents_count(); |
|
|
|
|
79
|
|
|
case 'fee_total' : |
80
|
|
|
return $this->totals->get_fees_total(); |
81
|
|
|
case 'shipping_total' : |
82
|
|
|
return $this->get_shipping_total( false ); |
|
|
|
|
83
|
|
|
case 'applied_coupons' : |
84
|
|
|
return array_keys( $this->get_coupons() ); |
|
|
|
|
85
|
|
|
case 'coupons' : |
86
|
|
|
return $this->get_coupons(); |
|
|
|
|
87
|
|
|
case 'total' : |
88
|
|
|
return $this->get_total(); |
|
|
|
|
89
|
|
|
case 'cart_contents_total' : |
90
|
|
|
return $this->totals->get_items_total(); |
91
|
|
|
case 'taxes' : |
92
|
|
|
return wc_list_pluck( $this->get_taxes(), 'get_tax_total' ); |
|
|
|
|
93
|
|
|
case 'shipping_taxes' : |
94
|
|
|
return wc_list_pluck( $this->get_taxes(), 'get_shipping_tax_total' ); |
|
|
|
|
95
|
|
|
case 'coupon_discount_amounts' : |
96
|
|
|
return $this->totals->get_coupon_totals(); |
97
|
|
|
case 'coupon_discount_tax_amounts' : |
98
|
|
|
return $this->totals->get_coupon_tax_totals(); |
99
|
|
|
case 'coupon_applied_count' : |
100
|
|
|
return $this->totals->get_coupon_counts(); |
101
|
|
|
} |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* @deprecated 2.7.0 |
106
|
|
|
*/ |
107
|
|
|
public function add_discount( $coupon_code ) { |
108
|
|
|
_deprecated_function( 'WC_Cart::add_discount', '2.7', 'WC_Cart::add_coupon' ); |
109
|
|
|
return $this->add_coupon( $coupon_code ); |
|
|
|
|
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* @deprecated 2.7.0 |
114
|
|
|
*/ |
115
|
|
|
public function has_discount( $coupon_code = '' ) { |
116
|
|
|
_deprecated_function( 'WC_Cart::has_discount', '2.7', 'WC_Cart::has_coupon' ); |
117
|
|
|
return $this->has_coupon( $coupon_code ); |
|
|
|
|
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* @deprecated 2.7.0 |
122
|
|
|
*/ |
123
|
|
|
public function get_applied_coupons() { |
124
|
|
|
_deprecated_function( 'WC_Cart::get_applied_coupons', '2.7', 'WC_Cart::get_coupons' ); |
125
|
|
|
return array_keys( $this->get_coupons() ); |
|
|
|
|
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* @deprecated 2.7.0 |
130
|
|
|
*/ |
131
|
|
|
public function check_cart_coupons() { |
132
|
|
|
_deprecated_function( 'WC_Cart::check_cart_coupons', '2.7', 'WC_Cart_Coupons::check_coupons' ); |
133
|
|
|
$this->coupons->check_coupons(); |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* @deprecated 2.7.0 |
138
|
|
|
*/ |
139
|
|
|
public function check_customer_coupons( $posted ) { |
140
|
|
|
_deprecated_function( 'WC_Cart::check_customer_coupons', '2.7', 'WC_Cart_Coupons::check_customer_restriction/check_customer_limits' ); |
141
|
|
|
$this->coupons->check_customer_restriction( $posted ); |
142
|
|
|
$this->coupons->check_customer_limits( $posted ); |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* @deprecated 2.7.0 |
147
|
|
|
*/ |
148
|
|
|
public function show_shipping() { |
149
|
|
|
_deprecated_function( 'WC_Cart::show_shipping', '2.7', 'wc_cart_show_shipping' ); |
150
|
|
|
return wc_cart_show_shipping(); |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* @deprecated 2.7.0 |
155
|
|
|
*/ |
156
|
|
|
public function calculate_fees() { |
157
|
|
|
_deprecated_function( 'WC_Cart::calculate_fees', '2.7', 'WC_Cart_Fees::calculate_fees' ); |
158
|
|
|
$this->fees->calculate_fees(); |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
/** |
162
|
|
|
* Add a product to the cart. |
163
|
|
|
* @deprecated 2.7.0 |
164
|
|
|
* @param int $product_id contains the id of the product to add to the cart |
165
|
|
|
* @param int $quantity contains the quantity of the item to add |
166
|
|
|
* @param int $variation_id |
167
|
|
|
* @param array $variation attribute values |
168
|
|
|
* @param array $cart_item_data extra cart item data we want to pass into the item |
169
|
|
|
* @return string|bool $cart_item_key |
170
|
|
|
*/ |
171
|
|
|
public function add_to_cart( $product_id = 0, $quantity = 1, $variation_id = 0, $variation = array(), $cart_item_data = array() ) { |
172
|
|
|
_deprecated_function( 'WC_Cart::add_to_cart', '2.7', 'wc_add_to_cart' ); |
173
|
|
|
|
174
|
|
|
// Map legacy args to new. |
175
|
|
|
if ( $variation_id ) { |
176
|
|
|
$product_id = $variation_id; |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
if ( $variation ) { |
|
|
|
|
180
|
|
|
$cart_item_data['variation'] = $variation; |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
return wc_add_to_cart( $product_id, $quantity, $cart_item_data ); |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
/** |
187
|
|
|
* Get cart items quantities - merged so we can do accurate stock checks on items across multiple lines. |
188
|
|
|
* @return array |
189
|
|
|
*/ |
190
|
|
|
public function get_cart_item_quantities() { |
191
|
|
|
_deprecated_function( 'WC_Cart::get_cart_item_quantities', '2.7', 'wc_cart_item_quantities' ); |
192
|
|
|
return wc_cart_item_quantities(); |
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
/** |
196
|
|
|
* @deprecated 2.7.0 |
197
|
|
|
*/ |
198
|
|
|
public function check_cart_items() { |
199
|
|
|
_deprecated_function( 'WC_Cart::check_cart_items', '2.7', 'WC_Cart_Items::check_items' ); |
200
|
|
|
$this->items->check_items(); |
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
/** |
204
|
|
|
* @deprecated 2.7.0 |
205
|
|
|
*/ |
206
|
|
|
public function check_cart_item_stock() { |
207
|
|
|
_doing_it_wrong( 'check_cart_item_stock', 'Should not be called directly.', '2.7' ); |
208
|
|
|
} |
209
|
|
|
|
210
|
|
|
/** |
211
|
|
|
* @deprecated 2.7.0 |
212
|
|
|
*/ |
213
|
|
|
public function persistent_cart_update() { |
214
|
|
|
_doing_it_wrong( 'persistent_cart_destroy', 'Should not be called directly.', '2.7' ); |
215
|
|
|
} |
216
|
|
|
|
217
|
|
|
/** |
218
|
|
|
* @deprecated 2.7.0 |
219
|
|
|
*/ |
220
|
|
|
public function persistent_cart_destroy() { |
221
|
|
|
_doing_it_wrong( 'persistent_cart_destroy', 'Should not be called directly.', '2.7' ); |
222
|
|
|
} |
223
|
|
|
|
224
|
|
|
/** |
225
|
|
|
* Determines the value that the customer spent and the subtotal |
226
|
|
|
* displayed, used for things like coupon validation. |
227
|
|
|
* |
228
|
|
|
* Since the coupon lines are displayed based on the TAX DISPLAY value |
229
|
|
|
* of cart, this is used to determine the spend. |
230
|
|
|
* |
231
|
|
|
* If cart totals are shown including tax, use the subtotal. |
232
|
|
|
* If cart totals are shown excluding tax, use the subtotal ex tax |
233
|
|
|
* (tax is shown after coupons). |
234
|
|
|
* @deprecated 2.7.0 |
235
|
|
|
* @since 2.6.0 |
236
|
|
|
* @return string |
237
|
|
|
*/ |
238
|
|
|
public function get_displayed_subtotal() { |
239
|
|
|
_deprecated_function( 'get_displayed_subtotal', '2.7', 'wc_cart_subtotal_to_display' ); |
240
|
|
|
return wc_cart_subtotal_to_display(); |
241
|
|
|
} |
242
|
|
|
|
243
|
|
|
/** |
244
|
|
|
* Get the product row price per item. |
245
|
|
|
* |
246
|
|
|
* @param WC_Product $product |
247
|
|
|
* @return string formatted price |
248
|
|
|
*/ |
249
|
|
|
public function get_product_price( $product ) { |
250
|
|
|
_deprecated_function( 'get_product_price', '2.7', 'wc_cart_product_price_html' ); |
251
|
|
|
return wc_cart_product_price_html( $product ); |
252
|
|
|
} |
253
|
|
|
|
254
|
|
|
/** |
255
|
|
|
* Gets the sub total (after calculation). |
256
|
|
|
* @deprecated 2.7.0 |
257
|
|
|
* @param bool $compound whether to include compound taxes |
258
|
|
|
* @return string formatted price |
259
|
|
|
*/ |
260
|
|
|
public function get_cart_subtotal( $compound = false ) { |
|
|
|
|
261
|
|
|
_deprecated_function( 'get_cart_subtotal', '2.7', 'wc_cart_subtotal_html' ); |
262
|
|
|
return wc_cart_subtotal_html( false, false ); |
263
|
|
|
} |
264
|
|
|
|
265
|
|
|
/** |
266
|
|
|
* Get the product row subtotal. |
267
|
|
|
* |
268
|
|
|
* Gets the tax etc to avoid rounding issues. |
269
|
|
|
* |
270
|
|
|
* When on the checkout (review order), this will get the subtotal based on the customer's tax rate rather than the base rate. |
271
|
|
|
* |
272
|
|
|
* @param WC_Product $product |
273
|
|
|
* @param int $quantity |
274
|
|
|
* @return string formatted price |
275
|
|
|
*/ |
276
|
|
|
public function get_product_subtotal( $product, $quantity ) { |
277
|
|
|
_deprecated_function( 'get_product_subtotal', '2.7', 'wc_cart_product_price_html' ); |
278
|
|
|
return wc_cart_product_price_html( $product, $quantity ); |
279
|
|
|
} |
280
|
|
|
|
281
|
|
|
/** |
282
|
|
|
* Gets the total discount amount. |
283
|
|
|
* @deprecated 2.7.0 in favor to get_cart_discount_total() |
284
|
|
|
*/ |
285
|
|
|
public function get_total_discount() { |
286
|
|
|
_deprecated_function( 'get_total_discount', '2.7', 'get_cart_discount_total' ); |
287
|
|
|
return wc_price( $this->get_cart_discount_total() ); |
|
|
|
|
288
|
|
|
} |
289
|
|
|
|
290
|
|
|
/** |
291
|
|
|
* Gets the url to the cart page. |
292
|
|
|
* |
293
|
|
|
* @deprecated 2.5.0 in favor to wc_get_cart_url() |
294
|
|
|
* @return string url to page |
295
|
|
|
*/ |
296
|
|
|
public function get_cart_url() { |
297
|
|
|
_deprecated_function( 'get_cart_url', '2.5', 'wc_get_cart_url' ); |
298
|
|
|
return wc_get_cart_url(); |
299
|
|
|
} |
300
|
|
|
|
301
|
|
|
/** |
302
|
|
|
* Gets the url to the checkout page. |
303
|
|
|
* |
304
|
|
|
* @deprecated 2.5.0 in favor to wc_get_checkout_url() |
305
|
|
|
* @return string url to page |
306
|
|
|
*/ |
307
|
|
|
public function get_checkout_url() { |
308
|
|
|
_deprecated_function( 'get_checkout_url', '2.5', 'wc_get_checkout_url' ); |
309
|
|
|
return wc_get_checkout_url(); |
310
|
|
|
} |
311
|
|
|
|
312
|
|
|
/** |
313
|
|
|
* Coupons enabled function. Filterable. |
314
|
|
|
* |
315
|
|
|
* @deprecated 2.5.0 in favor to wc_coupons_enabled() |
316
|
|
|
* @return bool |
317
|
|
|
*/ |
318
|
|
|
public function coupons_enabled() { |
319
|
|
|
_deprecated_function( 'coupons_enabled', '2.5', 'wc_coupons_enabled' ); |
320
|
|
|
return wc_coupons_enabled(); |
321
|
|
|
} |
322
|
|
|
|
323
|
|
|
/** |
324
|
|
|
* Sees if we need a shipping address. |
325
|
|
|
* |
326
|
|
|
* @deprecated 2.5.0 in favor to wc_ship_to_billing_address_only() |
327
|
|
|
* @return bool |
328
|
|
|
*/ |
329
|
|
|
public function ship_to_billing_address_only() { |
330
|
|
|
_deprecated_function( 'ship_to_billing_address_only', '2.5', 'wc_ship_to_billing_address_only' ); |
331
|
|
|
return wc_ship_to_billing_address_only(); |
332
|
|
|
} |
333
|
|
|
|
334
|
|
|
/** |
335
|
|
|
* @deprecated 2.7.0 |
336
|
|
|
*/ |
337
|
|
|
public function get_cross_sells() { |
338
|
|
|
_deprecated_function( 'WC_Cart::get_cross_sells', '2.7', 'wc_get_cart_cross_sells' ); |
339
|
|
|
wc_get_cart_cross_sells(); |
340
|
|
|
} |
341
|
|
|
|
342
|
|
|
/** |
343
|
|
|
* @deprecated 2.7.0 |
344
|
|
|
*/ |
345
|
|
|
public function get_remove_url( $cart_item_key ) { |
346
|
|
|
_deprecated_function( 'WC_Cart::get_remove_url', '2.7', 'wc_get_cart_remove_url' ); |
347
|
|
|
return wc_get_cart_remove_url( $cart_item_key ); |
348
|
|
|
} |
349
|
|
|
|
350
|
|
|
/** |
351
|
|
|
* @deprecated 2.7.0 |
352
|
|
|
*/ |
353
|
|
|
public function get_undo_url( $cart_item_key ) { |
354
|
|
|
_deprecated_function( 'WC_Cart::get_undo_url', '2.7', 'wc_get_cart_undo_url' ); |
355
|
|
|
return wc_get_cart_undo_url( $cart_item_key ); |
356
|
|
|
} |
357
|
|
|
|
358
|
|
|
/** |
359
|
|
|
* @deprecated 2.7.0 |
360
|
|
|
*/ |
361
|
|
|
public function get_discounted_price( $values, $price, $add_totals = false ) { |
|
|
|
|
362
|
|
|
_deprecated_function( 'WC_Cart::get_undo_url', '2.7' ); |
363
|
|
|
return $price; |
364
|
|
|
} |
365
|
|
|
|
366
|
|
|
/** |
367
|
|
|
* @deprecated 2.7.0 |
368
|
|
|
*/ |
369
|
|
|
public function get_item_data( $cart_item, $flat = false ) { |
|
|
|
|
370
|
|
|
_deprecated_function( 'WC_Cart::get_item_data', '2.7', 'wc_display_item_data' ); |
371
|
|
|
return wc_display_item_data( $cart_item, $flat = false ); |
372
|
|
|
} |
373
|
|
|
|
374
|
|
|
/** |
375
|
|
|
* @deprecated 2.7.0 Unused method. |
376
|
|
|
*/ |
377
|
|
|
public function get_total_ex_tax() { |
378
|
|
|
_deprecated_function( 'WC_Cart::get_total_ex_tax', '2.7' ); |
379
|
|
|
return apply_filters( 'woocommerce_cart_total_ex_tax', wc_price( min( 0, $this->total - $this->tax_total - $this->shipping_tax_total ) ) ); |
380
|
|
|
} |
381
|
|
|
|
382
|
|
|
/** |
383
|
|
|
* @deprecated 2.7.0 Unused method. |
384
|
|
|
*/ |
385
|
|
|
public function init() { |
386
|
|
|
_deprecated_function( 'WC_Cart::init', '2.7' ); |
387
|
|
|
} |
388
|
|
|
|
389
|
|
|
/** |
390
|
|
|
* @deprecated 2.7.0 Taxes are just not calculated when not needed, so no need to remove them. |
391
|
|
|
*/ |
392
|
|
|
public function remove_taxes() { |
393
|
|
|
_deprecated_function( 'WC_Cart::remove_taxes', '2.7' ); |
394
|
|
|
} |
395
|
|
|
|
396
|
|
|
/** |
397
|
|
|
* @deprecated 2.7.0 |
398
|
|
|
*/ |
399
|
|
|
public function find_product_in_cart( $cart_id = false ) { |
400
|
|
|
_deprecated_function( 'WC_Cart::find_product_in_cart', '2.7', 'WC_Cart::get_item_by_key' ); |
401
|
|
|
if ( $cart_id !== false ) { |
402
|
|
|
if ( is_array( $this->cart_contents ) && isset( $this->cart_contents[ $cart_id ] ) ) { |
403
|
|
|
return $cart_id; |
404
|
|
|
} |
405
|
|
|
} |
406
|
|
|
return ''; |
407
|
|
|
} |
408
|
|
|
|
409
|
|
|
/** |
410
|
|
|
* Generate a unique ID for the cart item being added. |
411
|
|
|
* @deprecated 2.7.0 |
412
|
|
|
* @param int $product_id - id of the product the key is being generated for |
413
|
|
|
* @param int $variation_id of the product the key is being generated for |
414
|
|
|
* @param array $variation data for the cart item |
415
|
|
|
* @param array $cart_item_data other cart item data passed which affects this items uniqueness in the cart |
416
|
|
|
* @return string cart item key |
417
|
|
|
*/ |
418
|
|
|
public function generate_cart_id( $product_id, $variation_id = 0, $variation = array(), $cart_item_data = array() ) { |
419
|
|
|
_deprecated_function( 'WC_Cart::generate_cart_id', '2.7', 'WC_Cart_Items::generate_key' ); |
420
|
|
|
return apply_filters( 'woocommerce_cart_id', md5( json_encode( array( $product_id, $variation_id, $variation, $cart_item_data ) ) ), $product_id, $variation_id, $variation, $cart_item_data ); |
421
|
|
|
} |
422
|
|
|
|
423
|
|
|
/** |
424
|
|
|
* @deprecated 2.7.0 |
425
|
|
|
*/ |
426
|
|
|
public function check_cart_item_validity() { |
427
|
|
|
_deprecated_function( 'WC_Cart::check_cart_item_validity', '2.7', 'WC_Cart_Items::check_items' ); |
428
|
|
|
$this->items->check_items(); |
429
|
|
|
} |
430
|
|
|
|
431
|
|
|
/** |
432
|
|
|
* @deprecated 2.7.0 Unused |
433
|
|
|
*/ |
434
|
|
|
public function get_cart_shipping_total() { |
435
|
|
|
_deprecated_function( 'WC_Cart::get_cart_shipping_total', '2.7' ); |
436
|
|
|
if ( isset( $this->shipping_total ) ) { |
437
|
|
|
if ( $this->shipping_total > 0 ) { |
438
|
|
|
|
439
|
|
|
// Display varies depending on settings |
440
|
|
|
if ( $this->tax_display_cart == 'excl' ) { |
441
|
|
|
|
442
|
|
|
$return = wc_price( $this->shipping_total ); |
443
|
|
|
|
444
|
|
View Code Duplication |
if ( $this->shipping_tax_total > 0 && wc_prices_include_tax() ) { |
|
|
|
|
445
|
|
|
$return .= ' <small class="tax_label">' . WC()->countries->ex_tax_or_vat() . '</small>'; |
446
|
|
|
} |
447
|
|
|
|
448
|
|
|
return $return; |
449
|
|
|
|
450
|
|
|
} else { |
451
|
|
|
|
452
|
|
|
$return = wc_price( $this->shipping_total + $this->shipping_tax_total ); |
453
|
|
|
|
454
|
|
View Code Duplication |
if ( $this->shipping_tax_total > 0 && ! wc_prices_include_tax() ) { |
|
|
|
|
455
|
|
|
$return .= ' <small class="tax_label">' . WC()->countries->inc_tax_or_vat() . '</small>'; |
456
|
|
|
} |
457
|
|
|
|
458
|
|
|
return $return; |
459
|
|
|
|
460
|
|
|
} |
461
|
|
|
} else { |
462
|
|
|
return __( 'Free!', 'woocommerce' ); |
463
|
|
|
} |
464
|
|
|
} |
465
|
|
|
return ''; |
466
|
|
|
} |
467
|
|
|
|
468
|
|
|
/** |
469
|
|
|
* @deprecated 2.7.0 Unused |
470
|
|
|
*/ |
471
|
|
|
public function get_tax_amount( $tax_rate_id ) { |
472
|
|
|
_deprecated_function( 'WC_Cart::get_tax_amount', '2.7', 'Obtain from WC_Cart::get_taxes' ); |
473
|
|
|
$taxes = $this->totals->get_taxes(); |
474
|
|
|
return isset( $taxes[ $tax_rate_id ] ) ? $taxes[ $tax_rate_id ]->get_tax_total() : 0; |
475
|
|
|
} |
476
|
|
|
|
477
|
|
|
/** |
478
|
|
|
* @deprecated 2.7.0 Unused |
479
|
|
|
*/ |
480
|
|
|
public function get_shipping_tax_amount( $tax_rate_id ) { |
481
|
|
|
_deprecated_function( 'WC_Cart::get_shipping_tax_amount', '2.7', 'Obtain from WC_Cart::get_taxes' ); |
482
|
|
|
$taxes = $this->totals->get_taxes(); |
483
|
|
|
return isset( $taxes[ $tax_rate_id ] ) ? $taxes[ $tax_rate_id ]->get_shipping_tax_total() : 0; |
484
|
|
|
} |
485
|
|
|
|
486
|
|
|
/** |
487
|
|
|
* @deprecated 2.7.0 Unused |
488
|
|
|
*/ |
489
|
|
|
public function get_cart_total() { |
490
|
|
|
_deprecated_function( 'WC_Cart::get_cart_total', '2.7' ); |
491
|
|
|
if ( ! wc_prices_include_tax() ) { |
492
|
|
|
$cart_contents_total = wc_price( $this->cart_contents_total ); |
493
|
|
|
} else { |
494
|
|
|
$cart_contents_total = wc_price( $this->cart_contents_total + $this->tax_total ); |
495
|
|
|
} |
496
|
|
|
return apply_filters( 'woocommerce_cart_contents_total', $cart_contents_total ); |
497
|
|
|
} |
498
|
|
|
|
499
|
|
|
/** |
500
|
|
|
* @deprecated 2.7.0 Unused |
501
|
|
|
*/ |
502
|
|
|
public function get_cart_tax() { |
503
|
|
|
_deprecated_function( 'WC_Cart::get_cart_tax', '2.7' ); |
504
|
|
|
$cart_total_tax = wc_round_tax_total( $this->tax_total + $this->shipping_tax_total ); |
505
|
|
|
return apply_filters( 'woocommerce_get_cart_tax', $cart_total_tax ? wc_price( $cart_total_tax ) : '' ); |
506
|
|
|
} |
507
|
|
|
} |
508
|
|
|
|
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the parent class: