1 | <?php |
||
14 | abstract class WC_Legacy_Customer extends WC_Data { |
||
15 | |||
16 | /** |
||
17 | * __isset legacy. |
||
18 | * @param mixed $key |
||
19 | * @return bool |
||
20 | */ |
||
21 | public function __isset( $key ) { |
||
22 | $legacy_keys = array( |
||
23 | 'id', 'country', 'state', 'postcode' ,'city', 'address_1', 'address', 'address_2', 'shipping_country', 'shipping_state', |
||
24 | 'shipping_postcode', 'shipping_city', 'shipping_address_1', 'shipping_address', 'shipping_address_2', 'is_vat_exempt', 'calculated_shipping', |
||
25 | ); |
||
26 | $key = $this->filter_legacy_key( $key ); |
||
27 | return in_array( $key, $legacy_keys ); |
||
28 | } |
||
29 | |||
30 | /** |
||
31 | * __get function. |
||
32 | * @todo use get_* methods |
||
33 | * @param string $key |
||
34 | * @return string |
||
35 | */ |
||
36 | public function __get( $key ) { |
||
37 | _doing_it_wrong( $key, 'Customer properties should not be accessed directly.', '2.7' ); |
||
38 | $key = $this->filter_legacy_key( $key ); |
||
39 | if ( in_array( $key, array( 'country', 'state', 'postcode' ,'city', 'address_1', 'address', 'address_2' ) ) ) { |
||
40 | $key = 'billing_' . $key; |
||
41 | } |
||
42 | return is_callable( array( $this, "get_{$key}" ) ) ? $this->{"get_{$key}"}() : ''; |
||
43 | } |
||
44 | |||
45 | /** |
||
46 | * __set function. |
||
47 | * @todo use set_* methods |
||
48 | * @param mixed $property |
||
|
|||
49 | * @param mixed $key |
||
50 | */ |
||
51 | public function __set( $key, $value ) { |
||
52 | _doing_it_wrong( $key, 'Customer properties should not be set directly.', '2.7' ); |
||
53 | $key = $this->filter_legacy_key( $key ); |
||
54 | |||
55 | if ( is_callable( array( $this, "set_{$key}" ) ) ) { |
||
56 | $this->{"set_{$key}"}( $value ); |
||
57 | } |
||
58 | } |
||
59 | |||
60 | /** |
||
61 | * Address and shipping_address are aliased, so we want to get the 'real' key name. |
||
62 | * For all other keys, we can just return it. |
||
63 | * @since 2.7.0 |
||
64 | * @param string $key |
||
65 | * @return string |
||
66 | */ |
||
67 | private function filter_legacy_key( $key ) { |
||
68 | if ( 'address' === $key ) { |
||
69 | $key = 'address_1'; |
||
70 | } |
||
71 | if ( 'shipping_address' === $key ) { |
||
72 | $key = 'shipping_address_1'; |
||
73 | } |
||
74 | return $key; |
||
75 | } |
||
76 | |||
77 | /** |
||
78 | * Sets session data for the location. |
||
79 | * |
||
80 | * @param string $country |
||
81 | * @param string $state |
||
82 | * @param string $postcode (default: '') |
||
83 | * @param string $city (default: '') |
||
84 | */ |
||
85 | public function set_location( $country, $state, $postcode = '', $city = '' ) { |
||
86 | $this->set_billing_location( $country, $state, $postcode, $city ); |
||
87 | $this->set_shipping_location( $country, $state, $postcode, $city ); |
||
88 | } |
||
89 | |||
90 | /** |
||
91 | * Get default country for a customer. |
||
92 | * @return string |
||
93 | */ |
||
94 | public function get_default_country() { |
||
99 | |||
100 | /** |
||
101 | * Get default state for a customer. |
||
102 | * @return string |
||
103 | */ |
||
104 | public function get_default_state() { |
||
109 | |||
110 | /** |
||
111 | * Set customer address to match shop base address. |
||
112 | */ |
||
113 | public function set_to_base() { |
||
114 | _deprecated_function( 'WC_Customer::set_to_base', '2.7', 'WC_Customer::set_billing_address_to_base' ); |
||
117 | |||
118 | /** |
||
119 | * Set customer shipping address to base address. |
||
120 | */ |
||
121 | public function set_shipping_to_base() { |
||
125 | |||
126 | /** |
||
127 | * Calculated shipping. |
||
128 | * @param boolean $calculated |
||
129 | */ |
||
130 | public function calculated_shipping( $calculated = true ) { |
||
134 | |||
135 | /** |
||
136 | * Set default data for a customer. |
||
137 | */ |
||
138 | public function set_default_data() { |
||
141 | |||
142 | /** |
||
143 | * Is the user a paying customer? |
||
144 | * @todo should this be moved to a get_ readonly? |
||
145 | * @return bool |
||
146 | */ |
||
147 | function is_paying_customer( $user_id = '' ) { |
||
154 | |||
155 | /** |
||
156 | * Legacy get country. |
||
157 | */ |
||
158 | function get_country() { |
||
162 | |||
163 | /** |
||
164 | * Legacy get state. |
||
165 | */ |
||
166 | function get_state() { |
||
170 | |||
171 | /** |
||
172 | * Legacy get postcode. |
||
173 | */ |
||
174 | function get_postcode() { |
||
178 | |||
179 | /** |
||
180 | * Legacy get city. |
||
181 | */ |
||
182 | function get_city() { |
||
186 | |||
187 | /** |
||
188 | * Legacy set country. |
||
189 | */ |
||
190 | function set_country( $country ) { |
||
194 | |||
195 | /** |
||
196 | * Legacy set state. |
||
197 | */ |
||
198 | function set_state( $state ) { |
||
202 | |||
203 | /** |
||
204 | * Legacy set postcode. |
||
205 | */ |
||
206 | function set_postcode( $postcode ) { |
||
210 | |||
211 | /** |
||
212 | * Legacy set city. |
||
213 | */ |
||
214 | function set_city( $city ) { |
||
218 | |||
219 | /** |
||
220 | * Legacy set address. |
||
221 | */ |
||
222 | function set_address( $address ) { |
||
226 | |||
227 | /** |
||
228 | * Legacy set address. |
||
229 | */ |
||
230 | function set_address_2( $address ) { |
||
234 | |||
235 | } |
||
236 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.