Completed
Pull Request — master (#11682)
by
unknown
08:38
created

WC_Customer::get_billing_company()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
include_once( 'legacy/class-wc-legacy-customer.php' );
3
4
if ( ! defined( 'ABSPATH' ) ) {
5
	exit;
6
}
7
8
/**
9
 * The WooCommerce customer class handles storage of the current customer's data, such as location.
10
 *
11
 * @class    WC_Customer
12
 * @version  2.7.0
13
 * @package  WooCommerce/Classes
14
 * @category Class
15
 * @author   WooThemes
16
 */
17
class WC_Customer extends WC_Legacy_Customer {
18
19
	/**
20
	 * Stores customer data.
21
	 * @var array
22
	 */
23
	protected $_data = array(
24
		'id'				   => 0,
25
		'email'                => '',
26
		'first_name'           => '',
27
		'last_name'            => '',
28
		'role'				   => 'customer',
29
		'last_order_id'        => null, // read only
30
		'last_order_date'      => null, // read only
31
		'orders_count'         => 0, // read only
32
		'total_spent'          => 0, // read only
33
		'username'             => '', // read only on existing users
34
		'password'             => '', // write only
35
		'date_created'         => '', // read only
36
		'date_modified'		   => '', // read only
37
		'billing_first_name'   => '',
38
		'billing_last_name'    => '',
39
		'billing_company'      => '',
40
		'billing_phone'        => '',
41
		'billing_email'        => '',
42
		'billing_postcode'     => '',
43
		'billing_city'         => '',
44
		'billing_address_1'    => '',
45
		'billing_address_2'    => '',
46
		'billing_state'        => '',
47
		'billing_country'      => '',
48
		'shipping_first_name'  => '',
49
		'shipping_last_name'   => '',
50
		'shipping_company'     => '',
51
		'shipping_postcode'    => '',
52
		'shipping_city'        => '',
53
		'shipping_address_1'   => '',
54
		'shipping_address_2'   => '',
55
		'shipping_state'       => '',
56
		'shipping_country'     => '',
57
		'is_paying_customer'   => false,
58
		'is_vat_exempt'        => false, // session only.
59
		'calculated_shipping'  => false, // session only
60
	);
61
62
	/**
63
	 * Keys which are also stored in a session (so we can make sure they get updated...)
64
	 * @var array
65
	 */
66
	protected $_session_keys = array(
67
		'billing_first_name', 'billing_last_name', 'billing_company', 'billing_postcode',
68
		'billing_city', 'billing_address_1', 'billing_address', 'billing_address_2',
69
		'billing_state', 'billing_country', 'shipping_first_name', 'shipping_last_name',
70
		'shipping_company', 'shipping_postcode', 'shipping_city', 'shipping_address_1',
71
		'shipping_address','shipping_address_2', 'shipping_state', 'shipping_country',
72
		'is_vat_exempt', 'calculated_shipping', 'billing_email', 'billing_phone',
73
	);
74
75
	/**
76
	 * Data stored in meta keys, but not considered "meta"
77
	 * @since 2.7.0
78
	 * @var array
79
	 */
80
	protected $_internal_meta_keys = array(
81
		'billing_first_name', 'billing_last_name', 'billing_company','billing_postcode',
82
		'billing_city', 'billing_address_1', 'billing_address_2', 'billing_state',
83
		'billing_country', 'shipping_first_name', 'shipping_last_name', 'shipping_company',
84
		'shipping_postcode', 'shipping_city', 'shipping_address_1', 'shipping_address_2',
85
		'shipping_state', 'shipping_country', 'paying_customer', 'last_update',
86
		'first_name', 'last_name', 'billing_email', 'billing_phone',
87
	);
88
89
	/**
90
	 * Internal meta type used to store user data.
91
	 * @var string
92
	 */
93
	protected $_meta_type = 'user';
94
95
	/**
96
	 * Was data changed in the database for this class?
97
	 * @var boolean
98
	 */
99
	protected $_changed = false;
100
101
	/**
102
	 * If some of the customer information is loaded by session (instead of just from the DB).
103
	 * @var boolean
104
	 */
105
	protected $_from_session = false;
106
107
	/**
108
	 * WC_Customer can also return an object for a logged out user (session).
109
	 * $_is_user will be false in this case. It will be true for all other cases
110
	 * (logged in users or getting a WC_Customer for another object)
111
	 * @var boolean
112
	 */
113
	protected $_is_user = false;
114
115
	/**
116
	 * Load customer data based on how WC_Customer is called.
117
	 * @param mixed $customer WC_Customer object or customer ID is accepted.
118
	 * if $customer is 'new', you can build a new WC_Customer object. If it's empty, some
119
	 * data will be pulled from the session for the current user/customer.
120
	 */
121
	public function __construct( $customer = '' ) {
122
		if ( $customer instanceof WC_Customer ) {
123
			$this->_is_user = true;
124
			$this->read( absint( $customer->get_id() ) );
125
		} elseif ( is_numeric( $customer ) ) {
126
			$this->_is_user = true;
127
			$this->read( $customer );
128
		} elseif ( empty( $customer ) ) {
129
			$this->_is_user = true; // unless load_session gets called after.
130
		}
131
132
		if ( $this->_from_session ) {
133
			add_action( 'shutdown', array( $this, 'save_session_if_changed' ), 10 );
134
		}
135
	}
136
137
	/**
138
	 * Saves customer information to the current session if any data changed.
139
	 * @since 2.7.0
140
	 */
141
	public function save_session_if_changed() {
142
		if ( $this->_changed ) {
143
			$this->save_to_session();
144
		}
145
	}
146
147
	/**
148
	 * Loads a WC session into the customer class.
149
	 */
150
	public function load_session() {
151
		$this->_from_session = true;
152
		if ( is_user_logged_in() ) {
153
			$this->_is_user = true;
154
			$this->read( get_current_user_id() );
155
		} else {
156
			$this->_is_user = false;
157
			$this->read( WC()->session->get_customer_id() );
158
		}
159
	}
160
161
	/*
162
	 |--------------------------------------------------------------------------
163
	 | Getters
164
	 |--------------------------------------------------------------------------
165
	 | Methods for getting data from the customer object.
166
	 */
167
168
	/**
169
	 * Return a customer's user ID. If the current customer is logged out, this will be a session key.
170
	 * @since 2.7.0
171
	 * @return mixed
172
	 */
173
	public function get_id() {
174
		return $this->_data['id'];
175
	}
176
177
	/**
178
	 * Return the customer's username.
179
	 * @since 2.7.0
180
	 * @return string
181
	 */
182
	public function get_username() {
183
		return $this->_data['username'];
184
	}
185
186
	/**
187
	 * Return the customer's email.
188
	 * @since 2.7.0
189
	 * @return string
190
	 */
191
	public function get_email() {
192
		return $this->_data['email'];
193
	}
194
195
	/**
196
	 * Return customer's first name.
197
	 * @since 2.7.0
198
	 * @return string
199
	 */
200
	public function get_first_name() {
201
		return $this->_data['first_name'];
202
	}
203
204
	/**
205
	 * Return customer's last name.
206
	 * @since 2.7.0
207
	 * @return string
208
	 */
209
	public function get_last_name() {
210
		return $this->_data['last_name'];
211
	}
212
213
	/**
214
	 * Return customer's user role.
215
	 * @since 2.7.0
216
	 * @return string
217
	 */
218
	public function get_role() {
219
		return $this->_data['role'];
220
	}
221
222
	/**
223
	 * Return customer's last order ID.
224
	 * @since 2.7.0
225
	 * @return integer|null
226
	 */
227
	public function get_last_order_id() {
228
		return ( is_null( $this->_data['last_order_id'] ) ? null : intval( $this->_data['last_order_id'] ) );
229
	}
230
231
	/**
232
	 * Return the date of the customer's last order.
233
	 * @since 2.7.0
234
	 * @return integer|null
235
	 */
236
	public function get_last_order_date() {
237
		return ( is_null( $this->_data['last_order_date'] ) ? null : intval( $this->_data['last_order_date'] ) );
238
	}
239
240
	/**
241
	 * Return the number of orders this customer has.
242
	 * @since 2.7.0
243
	 * @return integer
244
	 */
245
	public function get_orders_count() {
246
		return intval( $this->_data['orders_count'] );
247
	}
248
249
	/**
250
	 * Return how much money this customer has spent.
251
	 * @since 2.7.0
252
	 * @return float
253
	 */
254
	public function get_total_spent() {
255
		return wc_format_decimal( $this->_data['total_spent'] );
256
	}
257
258
	/**
259
	 * Return this customer's avatar.
260
	 * @since 2.7.0
261
	 * @return string
262
	 */
263 View Code Duplication
	public function get_avatar_url() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
264
		$avatar_html = get_avatar( $this->get_email() );
265
266
		// Get the URL of the avatar from the provided HTML
267
		preg_match( '/src=["|\'](.+)[\&|"|\']/U', $avatar_html, $matches );
268
269
		if ( isset( $matches[1] ) && ! empty( $matches[1] ) ) {
270
			return esc_url( $matches[1] );
271
		}
272
273
		return '';
274
	}
275
276
	/**
277
	 * Return the date this customer was created.
278
	 * @since 2.7.0
279
	 * @return integer
280
	 */
281
	public function get_date_created() {
282
		return absint( $this->_data['date_created'] );
283
	}
284
285
	/**
286
	 * Return the date this customer was last updated.
287
	 * @since 2.7.0
288
	 * @return integer
289
	 */
290
	public function get_date_modified() {
291
		return absint( $this->_data['date_modified'] );
292
	}
293
294
	/**
295
	 * Gets customer billing first name.
296
	 * @return string
297
	 */
298
	public function get_billing_first_name() {
299
		return $this->_data['billing_first_name'];
300
	}
301
302
	/**
303
	 * Gets customer billing last name.
304
	 * @return string
305
	 */
306
	public function get_billing_last_name() {
307
		return $this->_data['billing_last_name'];
308
	}
309
310
	/**
311
	 * Gets customer billing company.
312
	 * @return string
313
	 */
314
	public function get_billing_company() {
315
		return $this->_data['billing_company'];
316
	}
317
318
	/**
319
	 * Gets customer postcode.
320
	 * @return string
321
	 */
322
	public function get_billing_postcode() {
323
		return wc_format_postcode( $this->_data['billing_postcode'], $this->get_billing_country() );
324
	}
325
326
	/**
327
	 * Get customer city.
328
	 * @return string
329
	 */
330
	public function get_billing_city() {
331
		return $this->_data['billing_city'];
332
	}
333
334
	/**
335
	 * Get customer address.
336
	 * @return string
337
	 */
338
	public function get_billing_address() {
339
		return $this->_data['billing_address_1'];
340
	}
341
342
	/**
343
	 * Get customer address.
344
	 * @return string
345
	 */
346
	public function get_billing_address_1() {
347
		return $this->get_billing_address();
348
	}
349
350
	/**
351
	 * Get customer's second address.
352
	 * @return string
353
	 */
354
	public function get_billing_address_2() {
355
		return $this->_data['billing_address_2'];
356
	}
357
358
	/**
359
	 * Get customer state.
360
	 * @return string
361
	 */
362
	public function get_billing_state() {
363
		return $this->_data['billing_state'];
364
	}
365
366
	/**
367
	 * Get customer country.
368
	 * @return string
369
	 */
370
	public function get_billing_country() {
371
		return $this->_data['billing_country'];
372
	}
373
374
	/**
375
	 * Gets customer billing phone.
376
	 * @return string
377
	 */
378
	public function get_billing_phone() {
379
		return $this->_data['billing_phone'];
380
	}
381
382
	/**
383
	 * Gets customer billing email.
384
	 * @return string
385
	 */
386
	public function get_billing_email() {
387
		return $this->_data['billing_email'];
388
	}
389
390
	/**
391
	 * Gets customer shipping first name.
392
	 * @return string
393
	 */
394
	public function get_shipping_first_name() {
395
		return $this->_data['shipping_first_name'];
396
	}
397
398
	/**
399
	 * Gets customer shipping last name.
400
	 * @return string
401
	 */
402
	public function get_shipping_last_name() {
403
		return $this->_data['shipping_last_name'];
404
	}
405
406
	/**
407
	 * Gets customer shipping company.
408
	 * @return string
409
	 */
410
	public function get_shipping_company() {
411
		return $this->_data['shipping_company'];
412
	}
413
414
	/**
415
	 * Get customer's shipping state.
416
	 * @return string
417
	 */
418
	public function get_shipping_state() {
419
		return $this->_data['shipping_state'];
420
	}
421
422
	/**
423
	 * Get customer's shipping country.
424
	 * @return string
425
	 */
426
	public function get_shipping_country() {
427
		return $this->_data['shipping_country'];
428
	}
429
430
	/**
431
	 * Get customer's shipping postcode.
432
	 * @return string
433
	 */
434
	public function get_shipping_postcode() {
435
		return wc_format_postcode( $this->_data['shipping_postcode'], $this->get_shipping_country() );
436
	}
437
438
	/**
439
	 * Get customer's shipping city.
440
	 * @return string
441
	 */
442
	public function get_shipping_city() {
443
		return $this->_data['shipping_city'];
444
	}
445
446
	/**
447
	 * Get customer's shipping address.
448
	 * @return string
449
	 */
450
	public function get_shipping_address() {
451
		return $this->_data['shipping_address_1'];
452
	}
453
454
	/**
455
	 * Get customer address.
456
	 * @return string
457
	 */
458
	public function get_shipping_address_1() {
459
		return $this->get_shipping_address();
460
	}
461
462
	/**
463
	 * Get customer's second shipping address.
464
	 * @return string
465
	 */
466
	public function get_shipping_address_2() {
467
		return $this->_data['shipping_address_2'];
468
	}
469
470
	/**
471
	 * Get if customer is VAT exempt?
472
	 * @since 2.7.0
473
	 * @return bool
474
	 */
475
	public function get_is_vat_exempt() {
476
		return ( ! empty( $this->_data['is_vat_exempt'] ) ) ? true : false;
477
	}
478
479
	/**
480
	 * Has customer calculated shipping?
481
	 * @return bool
482
	 */
483
	public function get_calculated_shipping() {
484
		return ! empty( $this->_data['calculated_shipping'] );
485
	}
486
487
	/**
488
	 * Get taxable address.
489
	 * @return array
490
	 */
491
	public function get_taxable_address() {
492
		$tax_based_on = get_option( 'woocommerce_tax_based_on' );
493
494
		// Check shipping method at this point to see if we need special handling
495
		if ( true === apply_filters( 'woocommerce_apply_base_tax_for_local_pickup', true ) && sizeof( array_intersect( wc_get_chosen_shipping_method_ids(), apply_filters( 'woocommerce_local_pickup_methods', array( 'legacy_local_pickup', 'local_pickup' ) ) ) ) > 0 ) {
496
			$tax_based_on = 'base';
497
		}
498
499
		if ( 'base' === $tax_based_on ) {
500
			$country  = WC()->countries->get_base_country();
501
			$state    = WC()->countries->get_base_state();
502
			$postcode = WC()->countries->get_base_postcode();
503
			$city     = WC()->countries->get_base_city();
504
		} elseif ( 'billing' === $tax_based_on ) {
505
			$country  = $this->get_billing_country();
506
			$state    = $this->get_billing_state();
507
			$postcode = $this->get_billing_postcode();
508
			$city     = $this->get_billing_city();
509
		} else {
510
			$country  = $this->get_shipping_country();
511
			$state    = $this->get_shipping_state();
512
			$postcode = $this->get_shipping_postcode();
513
			$city     = $this->get_shipping_city();
514
		}
515
516
		return apply_filters( 'woocommerce_customer_taxable_address', array( $country, $state, $postcode, $city ) );
517
	}
518
519
	/**
520
	 * Gets a customer's downloadable products.
521
	 * @return array Array of downloadable products
522
	 */
523
	public function get_downloadable_products() {
524
		$downloads = array();
525
		if ( $this->_is_user ) {
526
			$downloads = wc_get_customer_available_downloads( $this->get_id() );
527
		}
528
		return apply_filters( 'woocommerce_customer_get_downloadable_products', $downloads );
529
	}
530
531
	/**
532
	 * Is the user a paying customer?
533
	 * @since 2.7.0
534
	 * @return bool
535
	 */
536
	function get_is_paying_customer() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
537
		return (bool) $this->_data['is_paying_customer'];
538
	}
539
540
	/*
541
	|--------------------------------------------------------------------------
542
	| Setters
543
	|--------------------------------------------------------------------------
544
	| Functions for setting customer data. These should not update anything in the
545
	| database itself and should only change what is stored in the class
546
	| object.
547
	*/
548
549
	/**
550
	 * Set customer's username.
551
	 * @since 2.7.0
552
	 * @param string $username
553
	 */
554
	public function set_username( $username ) {
555
		$this->_data['username'] = $username;
556
	}
557
558
	/**
559
	 * Set customer's email.
560
	 * @since 2.7.0
561
	 * @param string $email
562
	 */
563
	public function set_email( $email ) {
564
		$this->_data['email'] = sanitize_email( $email );
565
	}
566
567
	/**
568
	 * Set customer's first name.
569
	 * @since 2.7.0
570
	 * @param string $first_name
571
	 */
572
	public function set_first_name( $first_name ) {
573
		$this->_data['first_name'] = $first_name;
574
	}
575
576
	/**
577
	 * Set customer's last name.
578
	 * @since 2.7.0
579
	 * @param string $last_name
580
	 */
581
	public function set_last_name( $last_name ) {
582
		$this->_data['last_name'] = $last_name;
583
	}
584
585
	/**
586
	 * Set customer's user role(s).
587
	 * @since 2.7.0
588
	 * @param mixed $role
589
	 */
590
	public function set_role( $role ) {
591
		$this->_data['role'] = $role;
592
	}
593
594
	/**
595
	 * Set customer's last order ID.
596
	 * @since 2.7.0
597
	 * @param integer|null $last_order_id
598
	 */
599
	public function set_last_order_id( $last_order_id ) {
600
		$this->_data['last_order_id'] = $last_order_id;
601
	}
602
603
	/**
604
	 * Set the date of the customer's last order.
605
	 * @since 2.7.0
606
	 * @param string|null $last_order_date
607
	 */
608
	public function set_last_order_date( $last_order_date ) {
609
		$this->_data['last_order_date'] = $last_order_date;
610
 	}
611
612
	/**
613
	 * Set the number of orders this customer has.
614
	 * @since 2.7.0
615
	 * @param integer $order_count
0 ignored issues
show
Documentation introduced by
There is no parameter named $order_count. Did you maybe mean $orders_count?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
616
	 */
617
	public function set_orders_count( $orders_count ) {
618
		$this->_data['orders_count'] = $orders_count;
619
	}
620
621
	/**
622
	 * Return how much money this customer has spent.
623
	 * @since 2.7.0
624
	 * @param float $total_spent
625
	 */
626
	public function set_total_spent( $total_spent ) {
627
		$this->_data['total_spent'] = $total_spent;
628
	}
629
630
	/**
631
	 * Set customer's password.
632
	 * @since 2.7.0
633
	 * @param string $password
634
	 */
635
	public function set_password( $password ) {
636
		$this->_data['password'] = wc_clean( $password );
637
	}
638
639
	/**
640
	 * Set the date this customer was last updated.
641
	 * @since 2.7.0
642
	 * @param integer $timestamp
643
	 */
644
	public function set_date_modified( $timestamp ) {
645
		$this->_data['date_modified'] = is_numeric( $timestamp ) ? $timestamp : strtotime( $timestamp );
646
	}
647
648
	/**
649
	 * Set the date this customer was last updated.
650
	 * @since 2.7.0
651
	 * @param integer $timestamp
652
	 */
653
	public function set_date_created( $timestamp ) {
654
		$this->_data['date_created'] = is_numeric( $timestamp ) ? $timestamp : strtotime( $timestamp );
655
	}
656
657
	/**
658
	 * Set customer address to match shop base address.
659
	 * @since 2.7.0
660
	 */
661 View Code Duplication
	public function set_billing_address_to_base() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
662
		$base = wc_get_customer_default_location();
663
		$this->_data['billing_country']  = $base['country'];
664
		$this->_data['billing_state']    = $base['state'];
665
		$this->_data['billing_postcode'] = '';
666
		$this->_data['billing_city']     = '';
667
	}
668
669
	/**
670
	 * Set customer shipping address to base address.
671
	 * @since 2.7.0
672
	 */
673 View Code Duplication
	public function set_shipping_address_to_base() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
674
		$base = wc_get_customer_default_location();
675
		$this->_data['shipping_country']  = $base['country'];
676
		$this->_data['shipping_state']    = $base['state'];
677
		$this->_data['shipping_postcode'] = '';
678
		$this->_data['shipping_city']     = '';
679
	}
680
681
	/**
682
	 * Sets all shipping info at once.
683
	 * @param string $country
684
	 * @param string $state
685
	 * @param string $postcode
686
	 * @param string $city
687
	 */
688
	public function set_shipping_location( $country, $state = '', $postcode = '', $city = '' ) {
689
		$this->_data['shipping_country']  = $country;
690
		$this->_data['shipping_state']    = $state;
691
		$this->_data['shipping_postcode'] = $postcode;
692
		$this->_data['shipping_city']     = $city;
693
	}
694
695
	/**
696
	 * Sets all address info at once.
697
	 * @param string $country
698
	 * @param string $state
699
	 * @param string $postcode
700
	 * @param string $city
701
	 */
702
	public function set_billing_location( $country, $state, $postcode = '', $city = '' ) {
703
		$this->_data['billing_country']  = $country;
704
		$this->_data['billing_state']    = $state;
705
		$this->_data['billing_postcode'] = $postcode;
706
		$this->_data['billing_city']     = $city;
707
	}
708
709
	/**
710
	 * Set customer country.
711
	 * @param mixed $country
712
	 */
713
	public function set_billing_country( $country ) {
714
		$this->_data['billing_country'] = $country;
715
	}
716
717
	/**
718
	 * Set customer state.
719
	 * @param mixed $state
720
	 */
721
	public function set_billing_state( $state ) {
722
		$this->_data['billing_state'] = $state;
723
	}
724
725
	/**
726
	 * Sets customer billing first name.
727
	 * @param string $first_name
728
	 */
729
	public function set_billing_first_name( $first_name ) {
730
		$this->_data['billing_first_name'] = $first_name;
731
	}
732
733
	/**
734
	 * Sets customer billing last name.
735
	 * @param string $last_name
736
	 */
737
	public function set_billing_last_name( $last_name ) {
738
		$this->_data['billing_last_name'] = $last_name;
739
	}
740
741
	/**
742
	 * Sets customer billing company.
743
	 * @param string $company.
0 ignored issues
show
Documentation introduced by
There is no parameter named $company.. Did you maybe mean $company?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
744
	 */
745
	public function set_billing_company( $company ) {
746
		$this->_data['billing_company'] = $company;
747
	}
748
749
	/**
750
	 * Sets customer billing phone.
751
	 * @param string $phone
752
	 */
753
	public function set_billing_phone( $phone ) {
754
		$this->_data['billing_phone'] = $phone;
755
	}
756
757
	/**
758
	 * Sets customer billing email.
759
	 * @param string $email
760
	 */
761
	public function set_billing_email( $email ) {
762
		$this->_data['billing_email'] = $email;
763
	}
764
765
	/**
766
	 * Sets customer postcode.
767
	 * @param mixed $postcode
768
	 */
769
	public function set_billing_postcode( $postcode ) {
770
		$this->_data['billing_postcode'] = $postcode;
771
	}
772
773
	/**
774
	 * Sets customer city.
775
	 * @param mixed $city
776
	 */
777
	public function set_billing_city( $city ) {
778
		$this->_data['billing_city'] = $city;
779
	}
780
781
	/**
782
	 * Set customer address.
783
	 * @param mixed $address
784
	 */
785
	public function set_billing_address( $address ) {
786
		$this->_data['billing_address_1'] = $address;
787
	}
788
789
	/**
790
	 * Set customer address.
791
	 * @param mixed $address
792
	 */
793
	public function set_billing_address_1( $address ) {
794
		$this->set_billing_address( $address );
795
	}
796
797
	/**
798
	 * Set customer's second address.
799
	 * @param mixed $address
800
	 */
801
	public function set_billing_address_2( $address ) {
802
		$this->_data['billing_address_2'] = $address;
803
	}
804
805
	/**
806
	 * Sets customer shipping first name.
807
	 * @param string $first_name
808
	 */
809
	public function set_shipping_first_name( $first_name ) {
810
		$this->_data['shipping_first_name'] = $first_name;
811
	}
812
813
	/**
814
	 * Sets customer shipping last name.
815
	 * @param string $last_name
816
	 */
817
	public function set_shipping_last_name( $last_name ) {
818
		$this->_data['shipping_last_name'] = $last_name;
819
	}
820
821
	/**
822
	 * Sets customer shipping company.
823
	 * @param string $company.
0 ignored issues
show
Documentation introduced by
There is no parameter named $company.. Did you maybe mean $company?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
824
	 */
825
	public function set_shipping_company( $company ) {
826
		$this->_data['shipping_company'] = $company;
827
	}
828
829
	/**
830
	 * Set shipping country.
831
	 * @param string $country
832
	 */
833
	public function set_shipping_country( $country ) {
834
		$this->_data['shipping_country'] = $country;
835
	}
836
837
	/**
838
	 * Set shipping state.
839
	 * @param string $state
840
	 */
841
	public function set_shipping_state( $state ) {
842
		$this->_data['shipping_state'] = $state;
843
	}
844
845
	/**
846
	 * Set shipping postcode.
847
	 * @param string $postcode
848
	 */
849
	public function set_shipping_postcode( $postcode ) {
850
		$this->_data['shipping_postcode'] = $postcode;
851
	}
852
853
	/**
854
	 * Sets shipping city.
855
	 * @param string $city
856
	 */
857
	public function set_shipping_city( $city ) {
858
		$this->_data['shipping_city'] = $city;
859
	}
860
861
	/**
862
	 * Set shipping address.
863
	 * @param string $address
864
	 */
865
	public function set_shipping_address( $address ) {
866
		$this->_data['shipping_address_1'] = $address;
867
	}
868
869
	/**
870
	 * Set customer shipping address.
871
	 * @param mixed $address
872
	 */
873
	public function set_shipping_address_1( $address ) {
874
		$this->set_shipping_address( $address );
875
	}
876
877
	/**
878
	 * Set second shipping address.
879
	 * @param string $address
880
	 */
881
	public function set_shipping_address_2( $address ) {
882
		$this->_data['shipping_address_2'] = $address;
883
	}
884
885
	/**
886
	 * Set if customer has tax exemption.
887
	 * @param bool $is_vat_exempt
888
	 */
889
	public function set_is_vat_exempt( $is_vat_exempt ) {
890
		$this->_data['is_vat_exempt'] = $is_vat_exempt;
891
	}
892
893
	/**
894
	 * Calculated shipping?
895
	 * @param boolean $calculated
896
	 */
897
	public function set_calculated_shipping( $calculated = true ) {
898
		$this->_data['calculated_shipping'] = $calculated;
899
	}
900
901
	/**
902
	 * Set if the user a paying customer.
903
	 * @since 2.7.0
904
	 * @param boolean $is_paying_customer
905
	 */
906
	function set_is_paying_customer( $is_paying_customer ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
907
		$this->_data['is_paying_customer'] = (bool) $is_paying_customer;
908
	}
909
910
	/*
911
	|--------------------------------------------------------------------------
912
	| Other methods
913
	|--------------------------------------------------------------------------
914
	| Other functions for interacting with customers.
915
	*/
916
917
	/**
918
	 * Is customer outside base country (for tax purposes)?
919
	 * @return bool
920
	 */
921
	public function is_customer_outside_base() {
922
		list( $country, $state ) = $this->get_taxable_address();
923
		if ( $country ) {
924
			$default = wc_get_base_location();
925
			if ( $default['country'] !== $country ) {
926
				return true;
927
			}
928
			if ( $default['state'] && $default['state'] !== $state ) {
929
				return true;
930
			}
931
		}
932
		return false;
933
	}
934
935
	/*
936
	 |--------------------------------------------------------------------------
937
	 | CRUD methods
938
	 |--------------------------------------------------------------------------
939
	 | Methods which create, read, update and delete from the database.
940
	 |
941
	 | A save method is included for convenience (chooses update or create based
942
	 | on if the order exists yet).
943
	 */
944
945
	 /**
946
	  * Create a customer.
947
	  * @since 2.7.0.
948
	  */
949
	public function create() {
950
		$customer_id = wc_create_new_customer( $this->get_email(), $this->get_username(), $this->_data['password'] );
951
		unset( $this->_data['password'] );
952
		if ( $customer_id ) {
953
			$this->_data['id'] = $customer_id;
954
			update_user_meta( $this->get_id(), 'billing_first_name', $this->get_billing_first_name() );
955
			update_user_meta( $this->get_id(), 'billing_last_name', $this->get_billing_last_name() );
956
			update_user_meta( $this->get_id(), 'billing_company', $this->get_billing_company() );
957
			update_user_meta( $this->get_id(), 'billing_phone', $this->get_billing_phone() );
958
			update_user_meta( $this->get_id(), 'billing_email', $this->get_billing_email() );
959
			update_user_meta( $this->get_id(), 'billing_postcode', $this->get_billing_postcode() );
960
			update_user_meta( $this->get_id(), 'billing_city', $this->get_billing_city() );
961
			update_user_meta( $this->get_id(), 'billing_address_1', $this->get_billing_address() );
962
			update_user_meta( $this->get_id(), 'billing_address_2', $this->get_billing_address_2() );
963
			update_user_meta( $this->get_id(), 'billing_state', $this->get_billing_state() );
964
			update_user_meta( $this->get_id(), 'billing_country', $this->get_billing_country() );
965
			update_user_meta( $this->get_id(), 'shipping_first_name', $this->get_shipping_first_name() );
966
			update_user_meta( $this->get_id(), 'shipping_last_name', $this->get_shipping_last_name() );
967
			update_user_meta( $this->get_id(), 'shipping_company', $this->get_shipping_company() );
968
			update_user_meta( $this->get_id(), 'shipping_postcode', $this->get_shipping_postcode() );
969
			update_user_meta( $this->get_id(), 'shipping_city', $this->get_shipping_city() );
970
			update_user_meta( $this->get_id(), 'shipping_address_1', $this->get_shipping_address() );
971
			update_user_meta( $this->get_id(), 'shipping_address_2', $this->get_shipping_address_2() );
972
			update_user_meta( $this->get_id(), 'shipping_state', $this->get_shipping_state() );
973
			update_user_meta( $this->get_id(), 'shipping_country', $this->get_shipping_country() );
974
			update_user_meta( $this->get_id(), 'paying_customer', $this->get_is_paying_customer() );
975
			$this->set_date_modified( time() );
976
			update_user_meta( $this->get_id(), 'last_update',  $this->get_date_modified() );
977
			update_user_meta( $this->get_id(), 'first_name', $this->get_first_name() );
978
			update_user_meta( $this->get_id(), 'last_name', $this->get_last_name() );
979
			wp_update_user( array( 'ID' => $this->get_id(), 'role' => $this->get_role() ) );
980
			$wp_user = new WP_User( $this->get_id() );
981
			$this->set_date_created( strtotime( $wp_user->user_registered ) );
982
			$this->save_meta_data();
983
		}
984
	}
985
986
	/**
987
	 * Read a customer from the database.
988
	 * @since 2.7.0
989
	 * @param integer $id
990
	 */
991
	public function read( $id ) {
992
		global $wpdb;
993
		$pull_from_db = true;
994
		$data         = array();
995
		if ( $this->_from_session ) {
996
			$data = (array) WC()->session->get( 'customer' );
997
			if ( ! empty( $data ) ) {
998
				$pull_from_db  = false;
999
				foreach ( $this->_session_keys as $session_key ) {
1000
					$function_key = $session_key;
1001
					if ( 'billing_' === substr( $session_key, 0, 8 ) ) {
1002
						$session_key = str_replace( 'billing_', '', $session_key );
1003
					}
1004
					if ( ! empty( $data[ $session_key ] ) && is_callable( array( $this, "set_{$function_key}" ) ) ) {
1005
						$this->{"set_{$function_key}"}( $data[ $session_key ] );
1006
					}
1007
				}
1008
			}
1009
		}
1010
1011
		if ( $this->_is_user ) {
1012
1013
			// Only continue reading if the customer exists.
1014
			$user_object = get_userdata( $id );
1015
			if ( empty( $user_object ) || empty ( $user_object->ID ) ) {
1016
				$this->_data['id'] = 0;
1017
				return;
1018
			}
1019
1020
			foreach ( array_keys( $this->_data ) as $key ) {
1021
				if ( 'billing_' === substr( $key, 0, 8 ) ) {
1022
					$session_key = str_replace( 'billing_', '', $key );
1023
				}
1024
				if ( ! $pull_from_db && ! empty( $data[ $session_key ] ) ) {
1025
					continue;
1026
				}
1027
1028
				$meta_value = get_user_meta( $id, $key, true );
1029
				if ( $meta_value && is_callable( array( $this, "set_{$key}" ) ) ) {
1030
					$this->{"set_{$key}"}( $meta_value );
1031
				}
1032
			}
1033
1034
			$this->set_is_paying_customer( get_user_meta( $id, 'paying_customer', true ) );
1035
			$wp_user = new WP_User( $id );
1036
			$this->set_email( $wp_user->user_email );
1037
			$this->set_username( $wp_user->user_login );
1038
			$this->set_date_created( strtotime( $wp_user->user_registered ) );
1039
			$this->set_date_modified( get_user_meta( $id, 'last_update', true ) );
1040
			$this->set_role( ( ! empty ( $wp_user->roles[0] ) ? $wp_user->roles[0] : 'customer' ) );
1041
1042
			// Get info about user's last order
1043
			$last_order = $wpdb->get_row( "SELECT id, post_date_gmt
1044
				FROM $wpdb->posts AS posts
1045
				LEFT JOIN {$wpdb->postmeta} AS meta on posts.ID = meta.post_id
1046
				WHERE meta.meta_key = '_customer_user'
1047
				AND   meta.meta_value = {$id}
1048
				AND   posts.post_type = 'shop_order'
1049
				AND   posts.post_status IN ( '" . implode( "','", array_keys( wc_get_order_statuses() ) ) . "' )
1050
				ORDER BY posts.ID DESC
1051
			" );
1052
1053
			$this->set_last_order_id( is_object( $last_order ) ? $last_order->id : null );
1054
			$this->set_last_order_date( is_object( $last_order ) ? strtotime( $last_order->post_date_gmt ) : null );
1055
1056
			// WC_Customer can't use wc_get_customer_order_count because get_order_types might not be loaded by the time a customer/session is
1057
1058
			$count = $wpdb->get_var( "SELECT COUNT(*)
1059
				FROM $wpdb->posts as posts
1060
1061
				LEFT JOIN {$wpdb->postmeta} AS meta ON posts.ID = meta.post_id
1062
1063
				WHERE   meta.meta_key       = '_customer_user'
1064
				AND     posts.post_type = 'shop_order'
1065
				AND     posts.post_status   IN ('" . implode( "','", array_keys( wc_get_order_statuses() ) )  . "')
1066
				AND     meta_value          = $id
1067
			" );
1068
1069
			$spent = $wpdb->get_var( "SELECT SUM(meta2.meta_value)
1070
				FROM $wpdb->posts as posts
1071
1072
				LEFT JOIN {$wpdb->postmeta} AS meta ON posts.ID = meta.post_id
1073
				LEFT JOIN {$wpdb->postmeta} AS meta2 ON posts.ID = meta2.post_id
1074
1075
				WHERE   meta.meta_key       = '_customer_user'
1076
				AND     meta.meta_value     = $id
1077
				AND     posts.post_type     = 'shop_order'
1078
				AND     posts.post_status   IN ( 'wc-completed', 'wc-processing' )
1079
				AND     meta2.meta_key      = '_order_total'
1080
			" );
1081
			if ( ! $spent ) {
1082
				$spent = 0;
1083
			}
1084
1085
			$this->set_orders_count( $count );
1086
			$this->set_total_spent( $spent );
1087
1088
			$this->read_meta_data();
1089
		}
1090
1091
		$this->_data['id'] = $id;
1092
1093
		$default = wc_get_customer_default_location();
1094
1095
		// Set some defaults if some of our values are still not set.
1096
		if ( empty( $this->get_billing_country() ) ) {
1097
			$this->set_billing_country( $default['country'] );
1098
		}
1099
1100
		if ( empty( $this->get_shipping_country() ) ) {
1101
			$this->set_shipping_country( $this->get_billing_country() );
1102
		}
1103
1104
		if ( empty( $this->get_billing_state() ) ) {
1105
			$this->set_billing_state( $default['state'] );
1106
		}
1107
1108
		if ( empty( $this->get_shipping_state() ) ) {
1109
			$this->set_shipping_state( $this->get_billing_state() );
1110
		}
1111
1112
		unset( $this->_data['password'] ); // password is write only, never ever read it
1113
	}
1114
1115
	/**
1116
	 * Update a customer.
1117
	 * @since 2.7.0
1118
	 */
1119
	public function update() {
1120
		$customer_ID = $this->get_id();
1121
1122
		wp_update_user( array( 'ID' => $customer_ID, 'user_email' => $this->get_email() ) );
1123
		// Only update password if a new one was set with set_password
1124
		if ( isset( $this->_data['password'] ) ) {
1125
			wp_update_user( array( 'ID' => $customer_ID, 'user_pass' => $this->_data['password'] ) );
1126
			unset( $this->_data['password'] );
1127
		}
1128
1129
		update_user_meta( $this->get_id(), 'billing_first_name', $this->get_billing_first_name() );
1130
		update_user_meta( $this->get_id(), 'billing_last_name', $this->get_billing_last_name() );
1131
		update_user_meta( $this->get_id(), 'billing_company', $this->get_billing_company() );
1132
		update_user_meta( $this->get_id(), 'billing_phone', $this->get_billing_phone() );
1133
		update_user_meta( $this->get_id(), 'billing_email', $this->get_billing_email() );
1134
		update_user_meta( $this->get_id(), 'billing_postcode', $this->get_billing_postcode() );
1135
		update_user_meta( $this->get_id(), 'billing_city', $this->get_billing_city() );
1136
		update_user_meta( $this->get_id(), 'billing_address_1', $this->get_billing_address() );
1137
		update_user_meta( $this->get_id(), 'billing_address_2', $this->get_billing_address_2() );
1138
		update_user_meta( $this->get_id(), 'billing_state', $this->get_billing_state() );
1139
		update_user_meta( $this->get_id(), 'billing_country', $this->get_billing_country() );
1140
		update_user_meta( $this->get_id(), 'shipping_first_name', $this->get_shipping_first_name() );
1141
		update_user_meta( $this->get_id(), 'shipping_last_name', $this->get_shipping_last_name() );
1142
		update_user_meta( $this->get_id(), 'shipping_company', $this->get_shipping_company() );
1143
		update_user_meta( $this->get_id(), 'shipping_postcode', $this->get_shipping_postcode() );
1144
		update_user_meta( $this->get_id(), 'shipping_city', $this->get_shipping_city() );
1145
		update_user_meta( $this->get_id(), 'shipping_address_1', $this->get_shipping_address() );
1146
		update_user_meta( $this->get_id(), 'shipping_address_2', $this->get_shipping_address_2() );
1147
		update_user_meta( $this->get_id(), 'shipping_state', $this->get_shipping_state() );
1148
		update_user_meta( $this->get_id(), 'shipping_country', $this->get_shipping_country() );
1149
		update_user_meta( $this->get_id(), 'paying_customer', $this->get_is_paying_customer() );
1150
		$this->set_date_modified( time() );
1151
		update_user_meta( $this->get_id(), 'last_update',  $this->get_date_modified() );
1152
		update_user_meta( $this->get_id(), 'first_name', $this->get_first_name() );
1153
		update_user_meta( $this->get_id(), 'last_name', $this->get_last_name() );
1154
		wp_update_user( array( 'ID' => $this->get_id(), 'role' => $this->get_role() ) );
1155
		$this->save_meta_data();
1156
	}
1157
1158
	/**
1159
	 * Delete a customer.
1160
	 * @since 2.7.0
1161
	 */
1162
	public function delete() {
1163
		if ( ! $this->get_id() ) {
1164
			return;
1165
		}
1166
		return wp_delete_user( $this->get_id() );
1167
	}
1168
1169
	/**
1170
	 * Delete a customer and reassign posts..
1171
	 *
1172
	 * @param int $reassign Reassign posts and links to new User ID.
1173
	 * @since 2.7.0
1174
	 */
1175
	public function delete_and_reassign( $reassign = null ) {
1176
		if ( ! $this->get_id() ) {
1177
			return;
1178
		}
1179
		return wp_delete_user( $this->get_id(), $reassign );
1180
	}
1181
1182
	/**
1183
	 * Save data. Create when creating a new user/class, update when editing
1184
	 * an existing user, and save session when working on a logged out guest
1185
	 * session.
1186
	 * @since 2.7.0
1187
	 */
1188
	public function save() {
1189
		if ( $this->_from_session && ! $this->_is_user ) {
1190
			$this->save_session_if_changed();
1191
			return;
1192
		}
1193
		if ( ! $this->_is_user ) {
1194
			$this->create();
1195
		} else {
1196
			if ( ! $this->get_id() ) {
1197
				$this->create();
1198
			} else {
1199
				$this->update();
1200
			}
1201
		}
1202
	}
1203
1204
	/**
1205
	 * Saves data to the session only (does not overwrite DB values).
1206
	 * @since 2.7.0
1207
	 */
1208
	public function save_to_session() {
1209
		if ( ! $this->_from_session ) {
1210
			return;
1211
		}
1212
		$data = array();
1213
		foreach ( $this->_session_keys as $session_key ) {
1214
			$function_key = $session_key;
1215
			if ( 'billing_' === substr( $session_key, 0, 8 ) ) {
1216
				$session_key = str_replace( 'billing_', '', $session_key );
1217
			}
1218
			$data[ $session_key ] = $this->{"get_$function_key"}();
1219
		}
1220
		WC()->session->set( 'customer', $data );
1221
	}
1222
1223
}
1224