/var/www/html_us/wp-content/plugins/woocommerce/includes/class-wc-customer.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
<?php
/**
 * The WooCommerce customer class handles storage of the current customer's data, such as location.
 *
 * @package WooCommerce\Classes
 * @version 3.0.0
 */

defined'ABSPATH' ) || exit;

require_once 
dirname__FILE__ ) . '/legacy/class-wc-legacy-customer.php';

/**
 * Customer class.
 */
class WC_Customer extends WC_Legacy_Customer {

    
/**
     * Stores customer data.
     *
     * @var array
     */
    
protected $data = array(
        
'date_created'       => null,
        
'date_modified'      => null,
        
'email'              => '',
        
'first_name'         => '',
        
'last_name'          => '',
        
'display_name'       => '',
        
'role'               => 'customer',
        
'username'           => '',
        
'billing'            => array(
            
'first_name' => '',
            
'last_name'  => '',
            
'company'    => '',
            
'address_1'  => '',
            
'address_2'  => '',
            
'city'       => '',
            
'postcode'   => '',
            
'country'    => '',
            
'state'      => '',
            
'email'      => '',
            
'phone'      => '',
        ),
        
'shipping'           => array(
            
'first_name' => '',
            
'last_name'  => '',
            
'company'    => '',
            
'address_1'  => '',
            
'address_2'  => '',
            
'city'       => '',
            
'postcode'   => '',
            
'country'    => '',
            
'state'      => '',
            
'phone'      => '',
        ),
        
'is_paying_customer' => false,
    );

    
/**
     * Stores a password if this needs to be changed. Write-only and hidden from _data.
     *
     * @var string
     */
    
protected $password '';

    
/**
     * Stores if user is VAT exempt for this session.
     *
     * @var string
     */
    
protected $is_vat_exempt false;

    
/**
     * Stores if user has calculated shipping in this session.
     *
     * @var string
     */
    
protected $calculated_shipping false;

    
/**
     * This is the name of this object type.
     *
     * @since 5.6.0
     * @var string
     */
    
protected $object_type 'customer';

    
/**
     * Load customer data based on how WC_Customer is called.
     *
     * If $customer is 'new', you can build a new WC_Customer object. If it's empty, some
     * data will be pulled from the session for the current user/customer.
     *
     * @param WC_Customer|int $data       Customer ID or data.
     * @param bool            $is_session True if this is the customer session.
     * @throws Exception If customer cannot be read/found and $data is set.
     */
    
public function __construct$data 0$is_session false ) {
        
parent::__construct$data );

        if ( 
$data instanceof WC_Customer ) {
            
$this->set_idabsint$data->get_id() ) );
        } elseif ( 
is_numeric$data ) ) {
            
$this->set_id$data );
        }

        
$this->data_store WC_Data_Store::load'customer' );

        
// If we have an ID, load the user from the DB.
        
if ( $this->get_id() ) {
            try {
                
$this->data_store->read$this );
            } catch ( 
Exception $e ) {
                
$this->set_id);
                
$this->set_object_readtrue );
            }
        } else {
            
$this->set_object_readtrue );
        }

        
// If this is a session, set or change the data store to sessions. Changes do not persist in the database.
        
if ( $is_session && isset( WC()->session ) ) {
            
$this->data_store WC_Data_Store::load'customer-session' );
            
$this->data_store->read$this );
        }
    }

    
/**
     * Delete a customer and reassign posts..
     *
     * @param int $reassign Reassign posts and links to new User ID.
     * @since 3.0.0
     * @return bool
     */
    
public function delete_and_reassign$reassign null ) {
        if ( 
$this->data_store ) {
            
$this->data_store->delete(
                
$this,
                array(
                    
'force_delete' => true,
                    
'reassign'     => $reassign,
                )
            );
            
$this->set_id);
            return 
true;
        }
        return 
false;
    }

    
/**
     * Is customer outside base country (for tax purposes)?
     *
     * @return bool
     */
    
public function is_customer_outside_base() {
        list( 
$country$state ) = $this->get_taxable_address();
        if ( 
$country ) {
            
$default wc_get_base_location();
            if ( 
$default['country'] !== $country ) {
                return 
true;
            }
            if ( 
$default['state'] && $default['state'] !== $state ) {
                return 
true;
            }
        }
        return 
false;
    }

    
/**
     * Return this customer's avatar.
     *
     * @since 3.0.0
     * @return string
     */
    
public function get_avatar_url() {
        return 
get_avatar_url$this->get_email() );
    }

    
/**
     * Get taxable address.
     *
     * @return array
     */
    
public function get_taxable_address() {
        
$tax_based_on get_option'woocommerce_tax_based_on' );

        
// Check shipping method at this point to see if we need special handling.
        
if ( true === apply_filters'woocommerce_apply_base_tax_for_local_pickup'true ) && countarray_intersectwc_get_chosen_shipping_method_ids(), apply_filters'woocommerce_local_pickup_methods', array( 'legacy_local_pickup''local_pickup' ) ) ) ) > ) {
            
$tax_based_on 'base';
        }

        if ( 
'base' === $tax_based_on ) {
            
$country  WC()->countries->get_base_country();
            
$state    WC()->countries->get_base_state();
            
$postcode WC()->countries->get_base_postcode();
            
$city     WC()->countries->get_base_city();
        } elseif ( 
'billing' === $tax_based_on ) {
            
$country  $this->get_billing_country();
            
$state    $this->get_billing_state();
            
$postcode $this->get_billing_postcode();
            
$city     $this->get_billing_city();
        } else {
            
$country  $this->get_shipping_country();
            
$state    $this->get_shipping_state();
            
$postcode $this->get_shipping_postcode();
            
$city     $this->get_shipping_city();
        }

        
/**
         * Filters the taxable address for a given customer.
         *
         * @since 3.0.0
         *
         * @param array  $taxable_address An array of country, state, postcode, and city for the customer's taxable address.
         * @param object $customer        The customer object for which the taxable address is being requested.
         *
         * @return array The filtered taxable address for the customer.
         */
        
return apply_filters'woocommerce_customer_taxable_address', array( $country$state$postcode$city ), $this );
    }

    
/**
     * Gets a customer's downloadable products.
     *
     * @return array Array of downloadable products
     */
    
public function get_downloadable_products() {
        
$downloads = array();
        if ( 
$this->get_id() ) {
            
$downloads wc_get_customer_available_downloads$this->get_id() );
        }
        return 
apply_filters'woocommerce_customer_get_downloadable_products'$downloads );
    }

    
/**
     * Is customer VAT exempt?
     *
     * @return bool
     */
    
public function is_vat_exempt() {
        return 
$this->get_is_vat_exempt();
    }

    
/**
     * Has calculated shipping?
     *
     * @return bool
     */
    
public function has_calculated_shipping() {
        return 
$this->get_calculated_shipping();
    }

    
/**
     * Indicates if the customer has a non-empty shipping address.
     *
     * Note that this does not indicate if the customer's shipping address
     * is complete, only that one or more fields are populated.
     *
     * @since 5.3.0
     *
     * @return bool
     */
    
public function has_shipping_address() {
        foreach ( 
$this->get_shipping() as $address_field ) {
            
// Trim guards against a case where a subset of saved shipping address fields contain whitespace.
            
if ( strlentrim$address_field ) ) > ) {
                return 
true;
            }
        }

        return 
false;
    }

    
/**
     * Get if customer is VAT exempt?
     *
     * @since 3.0.0
     * @return bool
     */
    
public function get_is_vat_exempt() {
        return 
$this->is_vat_exempt;
    }

    
/**
     * Get password (only used when updating the user object).
     *
     * @return string
     */
    
public function get_password() {
        return 
$this->password;
    }

    
/**
     * Has customer calculated shipping?
     *
     * @return bool
     */
    
public function get_calculated_shipping() {
        return 
$this->calculated_shipping;
    }

    
/**
     * Set if customer has tax exemption.
     *
     * @param bool $is_vat_exempt If is vat exempt.
     */
    
public function set_is_vat_exempt$is_vat_exempt ) {
        
$this->is_vat_exempt wc_string_to_bool$is_vat_exempt );
    }

    
/**
     * Calculated shipping?
     *
     * @param bool $calculated If shipping is calculated.
     */
    
public function set_calculated_shipping$calculated true ) {
        
$this->calculated_shipping wc_string_to_bool$calculated );
    }

    
/**
     * Set customer's password.
     *
     * @since 3.0.0
     * @param string $password Password.
     */
    
public function set_password$password ) {
        
$this->password $password;
    }

    
/**
     * Gets the customers last order.
     *
     * @return WC_Order|false
     */
    
public function get_last_order() {
        return 
$this->data_store->get_last_order$this );
    }

    
/**
     * Return the number of orders this customer has.
     *
     * @return integer
     */
    
public function get_order_count() {
        return 
$this->data_store->get_order_count$this );
    }

    
/**
     * Return how much money this customer has spent.
     *
     * @return float
     */
    
public function get_total_spent() {
        return 
$this->data_store->get_total_spent$this );
    }

    
/*
    |--------------------------------------------------------------------------
    | Getters
    |--------------------------------------------------------------------------
    */

    /**
     * Return the customer's username.
     *
     * @since  3.0.0
     * @param  string $context What the value is for. Valid values are 'view' and 'edit'.
     * @return string
     */
    
public function get_username$context 'view' ) {
        return 
$this->get_prop'username'$context );
    }

    
/**
     * Return the customer's email.
     *
     * @since  3.0.0
     * @param  string $context What the value is for. Valid values are 'view' and 'edit'.
     * @return string
     */
    
public function get_email$context 'view' ) {
        return 
$this->get_prop'email'$context );
    }

    
/**
     * Return customer's first name.
     *
     * @since  3.0.0
     * @param  string $context What the value is for. Valid values are 'view' and 'edit'.
     * @return string
     */
    
public function get_first_name$context 'view' ) {
        return 
$this->get_prop'first_name'$context );
    }

    
/**
     * Return customer's last name.
     *
     * @since  3.0.0
     * @param  string $context What the value is for. Valid values are 'view' and 'edit'.
     * @return string
     */
    
public function get_last_name$context 'view' ) {
        return 
$this->get_prop'last_name'$context );
    }

    
/**
     * Return customer's display name.
     *
     * @since  3.1.0
     * @param  string $context What the value is for. Valid values are 'view' and 'edit'.
     * @return string
     */
    
public function get_display_name$context 'view' ) {
        return 
$this->get_prop'display_name'$context );
    }

    
/**
     * Return customer's user role.
     *
     * @since  3.0.0
     * @param  string $context What the value is for. Valid values are 'view' and 'edit'.
     * @return string
     */
    
public function get_role$context 'view' ) {
        return 
$this->get_prop'role'$context );
    }

    
/**
     * Return the date this customer was created.
     *
     * @since  3.0.0
     * @param  string $context What the value is for. Valid values are 'view' and 'edit'.
     * @return WC_DateTime|null object if the date is set or null if there is no date.
     */
    
public function get_date_created$context 'view' ) {
        return 
$this->get_prop'date_created'$context );
    }

    
/**
     * Return the date this customer was last updated.
     *
     * @since  3.0.0
     * @param  string $context What the value is for. Valid values are 'view' and 'edit'.
     * @return WC_DateTime|null object if the date is set or null if there is no date.
     */
    
public function get_date_modified$context 'view' ) {
        return 
$this->get_prop'date_modified'$context );
    }

    
/**
     * Gets a prop for a getter method.
     *
     * @since  3.0.0
     * @param  string $prop Name of prop to get.
     * @param  string $address_type Type of address; 'billing' or 'shipping'.
     * @param  string $context What the value is for. Valid values are 'view' and 'edit'.
     * @return mixed
     */
    
protected function get_address_prop$prop$address_type 'billing'$context 'view' ) {
        
$value null;

        if ( 
array_key_exists$prop$this->data$address_type ] ) ) {
            
$value = isset( $this->changes$address_type ][ $prop ] ) ? $this->changes$address_type ][ $prop ] : $this->data$address_type ][ $prop ];

            if ( 
'view' === $context ) {
                
/**
                 * Filter: 'woocommerce_customer_get_[billing|shipping]_[prop]'
                 *
                 * Allow developers to change the returned value for any customer address property.
                 *
                 * @since 3.6.0
                 * @param string      $value    The address property value.
                 * @param WC_Customer $customer The customer object being read.
                 */
                
$value apply_filters$this->get_hook_prefix() . $address_type '_' $prop$value$this );
            }
        }
        return 
$value;
    }

    
/**
     * Get billing.
     *
     * @since  3.2.0
     * @param  string $context What the value is for. Valid values are 'view' and 'edit'.
     * @return array
     */
    
public function get_billing$context 'view' ) {
        
$value null;
        
$prop  'billing';

        if ( 
array_key_exists$prop$this->data ) ) {
            
$changes array_key_exists$prop$this->changes ) ? $this->changes$prop ] : array();
            
$value   array_merge$this->data$prop ], $changes );

            if ( 
'view' === $context ) {
                
$value apply_filters$this->get_hook_prefix() . $prop$value$this );
            }
        }

        return 
$value;
    }

    
/**
     * Get billing_first_name.
     *
     * @param  string $context What the value is for. Valid values are 'view' and 'edit'.
     * @return string
     */
    
public function get_billing_first_name$context 'view' ) {
        return 
$this->get_address_prop'first_name''billing'$context );
    }

    
/**
     * Get billing_last_name.
     *
     * @param  string $context What the value is for. Valid values are 'view' and 'edit'.
     * @return string
     */
    
public function get_billing_last_name$context 'view' ) {
        return 
$this->get_address_prop'last_name''billing'$context );
    }

    
/**
     * Get billing_company.
     *
     * @param  string $context What the value is for. Valid values are 'view' and 'edit'.
     * @return string
     */
    
public function get_billing_company$context 'view' ) {
        return 
$this->get_address_prop'company''billing'$context );
    }

    
/**
     * Get billing_address_1.
     *
     * @param  string $context What the value is for. Valid values are 'view' and 'edit'.
     * @return string
     */
    
public function get_billing_address$context 'view' ) {
        return 
$this->get_billing_address_1$context );
    }

    
/**
     * Get billing_address_1.
     *
     * @param  string $context What the value is for. Valid values are 'view' and 'edit'.
     * @return string
     */
    
public function get_billing_address_1$context 'view' ) {
        return 
$this->get_address_prop'address_1''billing'$context );
    }

    
/**
     * Get billing_address_2.
     *
     * @param  string $context What the value is for. Valid values are 'view' and 'edit'.
     * @return string $value
     */
    
public function get_billing_address_2$context 'view' ) {
        return 
$this->get_address_prop'address_2''billing'$context );
    }

    
/**
     * Get billing_city.
     *
     * @param  string $context What the value is for. Valid values are 'view' and 'edit'.
     * @return string $value
     */
    
public function get_billing_city$context 'view' ) {
        return 
$this->get_address_prop'city''billing'$context );
    }

    
/**
     * Get billing_state.
     *
     * @param  string $context What the value is for. Valid values are 'view' and 'edit'.
     * @return string
     */
    
public function get_billing_state$context 'view' ) {
        return 
$this->get_address_prop'state''billing'$context );
    }

    
/**
     * Get billing_postcode.
     *
     * @param  string $context What the value is for. Valid values are 'view' and 'edit'.
     * @return string
     */
    
public function get_billing_postcode$context 'view' ) {
        return 
$this->get_address_prop'postcode''billing'$context );
    }

    
/**
     * Get billing_country.
     *
     * @param  string $context What the value is for. Valid values are 'view' and 'edit'.
     * @return string
     */
    
public function get_billing_country$context 'view' ) {
        return 
$this->get_address_prop'country''billing'$context );
    }

    
/**
     * Get billing_email.
     *
     * @param  string $context What the value is for. Valid values are 'view' and 'edit'.
     * @return string
     */
    
public function get_billing_email$context 'view' ) {
        return 
$this->get_address_prop'email''billing'$context );
    }

    
/**
     * Get billing_phone.
     *
     * @param  string $context What the value is for. Valid values are 'view' and 'edit'.
     * @return string
     */
    
public function get_billing_phone$context 'view' ) {
        return 
$this->get_address_prop'phone''billing'$context );
    }

    
/**
     * Get shipping.
     *
     * @since  3.2.0
     * @param  string $context What the value is for. Valid values are 'view' and 'edit'.
     * @return array
     */
    
public function get_shipping$context 'view' ) {
        
$value null;
        
$prop  'shipping';

        if ( 
array_key_exists$prop$this->data ) ) {
            
$changes array_key_exists$prop$this->changes ) ? $this->changes$prop ] : array();
            
$value   array_merge$this->data$prop ], $changes );

            if ( 
'view' === $context ) {
                
$value apply_filters$this->get_hook_prefix() . $prop$value$this );
            }
        }

        return 
$value;
    }

    
/**
     * Get shipping_first_name.
     *
     * @param  string $context What the value is for. Valid values are 'view' and 'edit'.
     * @return string
     */
    
public function get_shipping_first_name$context 'view' ) {
        return 
$this->get_address_prop'first_name''shipping'$context );
    }

    
/**
     * Get shipping_last_name.
     *
     * @param  string $context What the value is for. Valid values are 'view' and 'edit'.
     * @return string
     */
    
public function get_shipping_last_name$context 'view' ) {
        return 
$this->get_address_prop'last_name''shipping'$context );
    }

    
/**
     * Get shipping_company.
     *
     * @param  string $context What the value is for. Valid values are 'view' and 'edit'.
     * @return string
     */
    
public function get_shipping_company$context 'view' ) {
        return 
$this->get_address_prop'company''shipping'$context );
    }

    
/**
     * Get shipping_address_1.
     *
     * @param  string $context What the value is for. Valid values are 'view' and 'edit'.
     * @return string
     */
    
public function get_shipping_address$context 'view' ) {
        return 
$this->get_shipping_address_1$context );
    }

    
/**
     * Get shipping_address_1.
     *
     * @param  string $context What the value is for. Valid values are 'view' and 'edit'.
     * @return string
     */
    
public function get_shipping_address_1$context 'view' ) {
        return 
$this->get_address_prop'address_1''shipping'$context );
    }

    
/**
     * Get shipping_address_2.
     *
     * @param  string $context What the value is for. Valid values are 'view' and 'edit'.
     * @return string
     */
    
public function get_shipping_address_2$context 'view' ) {
        return 
$this->get_address_prop'address_2''shipping'$context );
    }

    
/**
     * Get shipping_city.
     *
     * @param  string $context What the value is for. Valid values are 'view' and 'edit'.
     * @return string
     */
    
public function get_shipping_city$context 'view' ) {
        return 
$this->get_address_prop'city''shipping'$context );
    }

    
/**
     * Get shipping_state.
     *
     * @param  string $context What the value is for. Valid values are 'view' and 'edit'.
     * @return string
     */
    
public function get_shipping_state$context 'view' ) {
        return 
$this->get_address_prop'state''shipping'$context );
    }

    
/**
     * Get shipping_postcode.
     *
     * @param  string $context What the value is for. Valid values are 'view' and 'edit'.
     * @return string
     */
    
public function get_shipping_postcode$context 'view' ) {
        return 
$this->get_address_prop'postcode''shipping'$context );
    }

    
/**
     * Get shipping_country.
     *
     * @param  string $context What the value is for. Valid values are 'view' and 'edit'.
     * @return string
     */
    
public function get_shipping_country$context 'view' ) {
        return 
$this->get_address_prop'country''shipping'$context );
    }

    
/**
     * Get shipping phone.
     *
     * @since 5.6.0
     * @param  string $context What the value is for. Valid values are 'view' and 'edit'.
     * @return string
     */
    
public function get_shipping_phone$context 'view' ) {
        return 
$this->get_address_prop'phone''shipping'$context );
    }

    
/**
     * Is the user a paying customer?
     *
     * @since  3.0.0
     * @param  string $context What the value is for. Valid values are 'view' and 'edit'.
     * @return bool
     */
    
public function get_is_paying_customer$context 'view' ) {
        return 
$this->get_prop'is_paying_customer'$context );
    }

    
/*
    |--------------------------------------------------------------------------
    | Setters
    |--------------------------------------------------------------------------
    */

    /**
     * Set customer's username.
     *
     * @since 3.0.0
     * @param string $username Username.
     */
    
public function set_username$username ) {
        
$this->set_prop'username'$username );
    }

    
/**
     * Set customer's email.
     *
     * @since 3.0.0
     * @param string $value Email.
     */
    
public function set_email$value ) {
        if ( 
$value && ! is_email$value ) ) {
            
$this->error'customer_invalid_email'__'Invalid email address''woocommerce' ) );
        }
        
$this->set_prop'email'sanitize_email$value ) );
    }

    
/**
     * Set customer's first name.
     *
     * @since 3.0.0
     * @param string $first_name First name.
     */
    
public function set_first_name$first_name ) {
        
$this->set_prop'first_name'$first_name );
    }

    
/**
     * Set customer's last name.
     *
     * @since 3.0.0
     * @param string $last_name Last name.
     */
    
public function set_last_name$last_name ) {
        
$this->set_prop'last_name'$last_name );
    }

    
/**
     * Set customer's display name.
     *
     * @since 3.1.0
     * @param string $display_name Display name.
     */
    
public function set_display_name$display_name ) {
        
/* translators: 1: first name 2: last name */
        
$this->set_prop'display_name'is_email$display_name ) ? sprintf_x'%1$s %2$s''display name''woocommerce' ), $this->get_first_name(), $this->get_last_name() ) : $display_name );
    }

    
/**
     * Set customer's user role(s).
     *
     * @since 3.0.0
     * @param mixed $role User role.
     */
    
public function set_role$role ) {
        global 
$wp_roles;

        if ( 
$role && ! empty( $wp_roles->roles ) && ! in_array$rolearray_keys$wp_roles->roles ), true ) ) {
            
$this->error'customer_invalid_role'__'Invalid role''woocommerce' ) );
        }
        
$this->set_prop'role'$role );
    }

    
/**
     * Set the date this customer was last updated.
     *
     * @since  3.0.0
     * @param  string|integer|null $date UTC timestamp, or ISO 8601 DateTime. If the DateTime string has no timezone or offset, WordPress site timezone will be assumed. Null if their is no date.
     */
    
public function set_date_created$date null ) {
        
$this->set_date_prop'date_created'$date );
    }

    
/**
     * Set the date this customer was last updated.
     *
     * @since  3.0.0
     * @param  string|integer|null $date UTC timestamp, or ISO 8601 DateTime. If the DateTime string has no timezone or offset, WordPress site timezone will be assumed. Null if their is no date.
     */
    
public function set_date_modified$date null ) {
        
$this->set_date_prop'date_modified'$date );
    }

    
/**
     * Set customer address to match shop base address.
     *
     * @since 3.0.0
     */
    
public function set_billing_address_to_base() {
        
$base wc_get_customer_default_location();
        
$this->set_billing_location$base['country'], $base['state'], '''' );
    }

    
/**
     * Set customer shipping address to base address.
     *
     * @since 3.0.0
     */
    
public function set_shipping_address_to_base() {
        
$base wc_get_customer_default_location();
        
$this->set_shipping_location$base['country'], $base['state'], '''' );
    }

    
/**
     * Sets all address info at once.
     *
     * @param string $country  Country.
     * @param string $state    State.
     * @param string $postcode Postcode.
     * @param string $city     City.
     */
    
public function set_billing_location$country$state ''$postcode ''$city '' ) {
        
$address_data $this->get_prop'billing''edit' );

        
$address_data['address_1'] = '';
        
$address_data['address_2'] = '';
        
$address_data['city']      = $city;
        
$address_data['state']     = $state;
        
$address_data['postcode']  = $postcode;
        
$address_data['country']   = $country;

        
$this->set_prop'billing'$address_data );
    }

    
/**
     * Sets all shipping info at once.
     *
     * @param string $country  Country.
     * @param string $state    State.
     * @param string $postcode Postcode.
     * @param string $city     City.
     */
    
public function set_shipping_location$country$state ''$postcode ''$city '' ) {
        
$address_data $this->get_prop'shipping''edit' );

        
$address_data['address_1'] = '';
        
$address_data['address_2'] = '';
        
$address_data['city']      = $city;
        
$address_data['state']     = $state;
        
$address_data['postcode']  = $postcode;
        
$address_data['country']   = $country;

        
$this->set_prop'shipping'$address_data );
    }

    
/**
     * Sets a prop for a setter method.
     *
     * @since 3.0.0
     * @param string $prop         Name of prop to set.
     * @param string $address_type Type of address; 'billing' or 'shipping'.
     * @param mixed  $value        Value of the prop.
     */
    
protected function set_address_prop$prop$address_type$value ) {
        if ( 
array_key_exists$prop$this->data$address_type ] ) ) {
            if ( 
true === $this->object_read ) {
                if ( 
$value !== $this->data$address_type ][ $prop ] || ( isset( $this->changes$address_type ] ) && array_key_exists$prop$this->changes$address_type ] ) ) ) {
                    
$this->changes$address_type ][ $prop ] = $value;
                }
            } else {
                
$this->data$address_type ][ $prop ] = $value;
            }
        }
    }

    
/**
     * Set billing_first_name.
     *
     * @param string $value Billing first name.
     */
    
public function set_billing_first_name$value ) {
        
$this->set_address_prop'first_name''billing'$value );
    }

    
/**
     * Set billing_last_name.
     *
     * @param string $value Billing last name.
     */
    
public function set_billing_last_name$value ) {
        
$this->set_address_prop'last_name''billing'$value );
    }

    
/**
     * Set billing_company.
     *
     * @param string $value Billing company.
     */
    
public function set_billing_company$value ) {
        
$this->set_address_prop'company''billing'$value );
    }

    
/**
     * Set billing_address_1.
     *
     * @param string $value Billing address line 1.
     */
    
public function set_billing_address$value ) {
        
$this->set_billing_address_1$value );
    }

    
/**
     * Set billing_address_1.
     *
     * @param string $value Billing address line 1.
     */
    
public function set_billing_address_1$value ) {
        
$this->set_address_prop'address_1''billing'$value );
    }

    
/**
     * Set billing_address_2.
     *
     * @param string $value Billing address line 2.
     */
    
public function set_billing_address_2$value ) {
        
$this->set_address_prop'address_2''billing'$value );
    }

    
/**
     * Set billing_city.
     *
     * @param string $value Billing city.
     */
    
public function set_billing_city$value ) {
        
$this->set_address_prop'city''billing'$value );
    }

    
/**
     * Set billing_state.
     *
     * @param string $value Billing state.
     */
    
public function set_billing_state$value ) {
        
$this->set_address_prop'state''billing'$value );
    }

    
/**
     * Set billing_postcode.
     *
     * @param string $value Billing postcode.
     */
    
public function set_billing_postcode$value ) {
        
$this->set_address_prop'postcode''billing'$value );
    }

    
/**
     * Set billing_country.
     *
     * @param string $value Billing country.
     */
    
public function set_billing_country$value ) {
        
$this->set_address_prop'country''billing'$value );
    }

    
/**
     * Set billing_email.
     *
     * @param string $value Billing email.
     */
    
public function set_billing_email$value ) {
        if ( 
$value && ! is_email$value ) ) {
            
$this->error'customer_invalid_billing_email'__'Invalid billing email address''woocommerce' ) );
        }
        
$this->set_address_prop'email''billing'sanitize_email$value ) );
    }

    
/**
     * Set billing_phone.
     *
     * @param string $value Billing phone.
     */
    
public function set_billing_phone$value ) {
        
$this->set_address_prop'phone''billing'$value );
    }

    
/**
     * Set shipping_first_name.
     *
     * @param string $value Shipping first name.
     */
    
public function set_shipping_first_name$value ) {
        
$this->set_address_prop'first_name''shipping'$value );
    }

    
/**
     * Set shipping_last_name.
     *
     * @param string $value Shipping last name.
     */
    
public function set_shipping_last_name$value ) {
        
$this->set_address_prop'last_name''shipping'$value );
    }

    
/**
     * Set shipping_company.
     *
     * @param string $value Shipping company.
     */
    
public function set_shipping_company$value ) {
        
$this->set_address_prop'company''shipping'$value );
    }

    
/**
     * Set shipping_address_1.
     *
     * @param string $value Shipping address line 1.
     */
    
public function set_shipping_address$value ) {
        
$this->set_shipping_address_1$value );
    }

    
/**
     * Set shipping_address_1.
     *
     * @param string $value Shipping address line 1.
     */
    
public function set_shipping_address_1$value ) {
        
$this->set_address_prop'address_1''shipping'$value );
    }

    
/**
     * Set shipping_address_2.
     *
     * @param string $value Shipping address line 2.
     */
    
public function set_shipping_address_2$value ) {
        
$this->set_address_prop'address_2''shipping'$value );
    }

    
/**
     * Set shipping_city.
     *
     * @param string $value Shipping city.
     */
    
public function set_shipping_city$value ) {
        
$this->set_address_prop'city''shipping'$value );
    }

    
/**
     * Set shipping_state.
     *
     * @param string $value Shipping state.
     */
    
public function set_shipping_state$value ) {
        
$this->set_address_prop'state''shipping'$value );
    }

    
/**
     * Set shipping_postcode.
     *
     * @param string $value Shipping postcode.
     */
    
public function set_shipping_postcode$value ) {
        
$this->set_address_prop'postcode''shipping'$value );
    }

    
/**
     * Set shipping_country.
     *
     * @param string $value Shipping country.
     */
    
public function set_shipping_country$value ) {
        
$this->set_address_prop'country''shipping'$value );
    }

    
/**
     * Set shipping phone.
     *
     * @since 5.6.0
     * @param string $value Shipping phone.
     */
    
public function set_shipping_phone$value ) {
        
$this->set_address_prop'phone''shipping'$value );
    }

    
/**
     * Set if the user a paying customer.
     *
     * @since 3.0.0
     * @param bool $is_paying_customer If is a paying customer.
     */
    
public function set_is_paying_customer$is_paying_customer ) {
        
$this->set_prop'is_paying_customer', (bool) $is_paying_customer );
    }
}