api
3 years ago
abstract-wc-legacy-order.php
5 years ago
abstract-wc-legacy-payment-token.php
5 years ago
abstract-wc-legacy-product.php
5 years ago
class-wc-legacy-api.php
4 years ago
class-wc-legacy-cart.php
5 years ago
class-wc-legacy-coupon.php
5 years ago
class-wc-legacy-customer.php
5 years ago
class-wc-legacy-shipping-zone.php
5 years ago
class-wc-legacy-webhook.php
5 years ago
class-wc-legacy-customer.php
287 lines
| 1 | <?php |
| 2 | if ( ! defined( 'ABSPATH' ) ) { |
| 3 | exit; |
| 4 | } |
| 5 | |
| 6 | /** |
| 7 | * Legacy Customer. |
| 8 | * |
| 9 | * @version 3.0.0 |
| 10 | * @package WooCommerce\Classes |
| 11 | * @category Class |
| 12 | * @author WooThemes |
| 13 | */ |
| 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', |
| 24 | 'country', |
| 25 | 'state', |
| 26 | 'postcode', |
| 27 | 'city', |
| 28 | 'address_1', |
| 29 | 'address', |
| 30 | 'address_2', |
| 31 | 'shipping_country', |
| 32 | 'shipping_state', |
| 33 | 'shipping_postcode', |
| 34 | 'shipping_city', |
| 35 | 'shipping_address_1', |
| 36 | 'shipping_address', |
| 37 | 'shipping_address_2', |
| 38 | 'is_vat_exempt', |
| 39 | 'calculated_shipping', |
| 40 | ); |
| 41 | $key = $this->filter_legacy_key( $key ); |
| 42 | return in_array( $key, $legacy_keys ); |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * __get function. |
| 47 | * @param string $key |
| 48 | * @return string |
| 49 | */ |
| 50 | public function __get( $key ) { |
| 51 | wc_doing_it_wrong( $key, 'Customer properties should not be accessed directly.', '3.0' ); |
| 52 | $key = $this->filter_legacy_key( $key ); |
| 53 | if ( in_array( $key, array( 'country', 'state', 'postcode', 'city', 'address_1', 'address', 'address_2' ) ) ) { |
| 54 | $key = 'billing_' . $key; |
| 55 | } |
| 56 | return is_callable( array( $this, "get_{$key}" ) ) ? $this->{"get_{$key}"}() : ''; |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * __set function. |
| 61 | * |
| 62 | * @param string $key |
| 63 | * @param mixed $value |
| 64 | */ |
| 65 | public function __set( $key, $value ) { |
| 66 | wc_doing_it_wrong( $key, 'Customer properties should not be set directly.', '3.0' ); |
| 67 | $key = $this->filter_legacy_key( $key ); |
| 68 | |
| 69 | if ( is_callable( array( $this, "set_{$key}" ) ) ) { |
| 70 | $this->{"set_{$key}"}( $value ); |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * Address and shipping_address are aliased, so we want to get the 'real' key name. |
| 76 | * For all other keys, we can just return it. |
| 77 | * @since 3.0.0 |
| 78 | * @param string $key |
| 79 | * @return string |
| 80 | */ |
| 81 | private function filter_legacy_key( $key ) { |
| 82 | if ( 'address' === $key ) { |
| 83 | $key = 'address_1'; |
| 84 | } |
| 85 | if ( 'shipping_address' === $key ) { |
| 86 | $key = 'shipping_address_1'; |
| 87 | } |
| 88 | |
| 89 | return $key; |
| 90 | } |
| 91 | |
| 92 | /** |
| 93 | * Sets session data for the location. |
| 94 | * |
| 95 | * @param string $country |
| 96 | * @param string $state |
| 97 | * @param string $postcode (default: '') |
| 98 | * @param string $city (default: '') |
| 99 | */ |
| 100 | public function set_location( $country, $state, $postcode = '', $city = '' ) { |
| 101 | $this->set_billing_location( $country, $state, $postcode, $city ); |
| 102 | $this->set_shipping_location( $country, $state, $postcode, $city ); |
| 103 | } |
| 104 | |
| 105 | /** |
| 106 | * Get default country for a customer. |
| 107 | * @return string |
| 108 | */ |
| 109 | public function get_default_country() { |
| 110 | wc_deprecated_function( 'WC_Customer::get_default_country', '3.0', 'wc_get_customer_default_location' ); |
| 111 | $default = wc_get_customer_default_location(); |
| 112 | return $default['country']; |
| 113 | } |
| 114 | |
| 115 | /** |
| 116 | * Get default state for a customer. |
| 117 | * @return string |
| 118 | */ |
| 119 | public function get_default_state() { |
| 120 | wc_deprecated_function( 'WC_Customer::get_default_state', '3.0', 'wc_get_customer_default_location' ); |
| 121 | $default = wc_get_customer_default_location(); |
| 122 | return $default['state']; |
| 123 | } |
| 124 | |
| 125 | /** |
| 126 | * Set customer address to match shop base address. |
| 127 | */ |
| 128 | public function set_to_base() { |
| 129 | wc_deprecated_function( 'WC_Customer::set_to_base', '3.0', 'WC_Customer::set_billing_address_to_base' ); |
| 130 | $this->set_billing_address_to_base(); |
| 131 | } |
| 132 | |
| 133 | /** |
| 134 | * Set customer shipping address to base address. |
| 135 | */ |
| 136 | public function set_shipping_to_base() { |
| 137 | wc_deprecated_function( 'WC_Customer::set_shipping_to_base', '3.0', 'WC_Customer::set_shipping_address_to_base' ); |
| 138 | $this->set_shipping_address_to_base(); |
| 139 | } |
| 140 | |
| 141 | /** |
| 142 | * Calculated shipping. |
| 143 | * @param boolean $calculated |
| 144 | */ |
| 145 | public function calculated_shipping( $calculated = true ) { |
| 146 | wc_deprecated_function( 'WC_Customer::calculated_shipping', '3.0', 'WC_Customer::set_calculated_shipping' ); |
| 147 | $this->set_calculated_shipping( $calculated ); |
| 148 | } |
| 149 | |
| 150 | /** |
| 151 | * Set default data for a customer. |
| 152 | */ |
| 153 | public function set_default_data() { |
| 154 | wc_deprecated_function( 'WC_Customer::set_default_data', '3.0' ); |
| 155 | } |
| 156 | |
| 157 | /** |
| 158 | * Save data function. |
| 159 | */ |
| 160 | public function save_data() { |
| 161 | $this->save(); |
| 162 | } |
| 163 | |
| 164 | /** |
| 165 | * Is the user a paying customer? |
| 166 | * |
| 167 | * @param int $user_id |
| 168 | * |
| 169 | * @return bool |
| 170 | */ |
| 171 | function is_paying_customer( $user_id = '' ) { |
| 172 | wc_deprecated_function( 'WC_Customer::is_paying_customer', '3.0', 'WC_Customer::get_is_paying_customer' ); |
| 173 | if ( ! empty( $user_id ) ) { |
| 174 | $user_id = get_current_user_id(); |
| 175 | } |
| 176 | return '1' === get_user_meta( $user_id, 'paying_customer', true ); |
| 177 | } |
| 178 | |
| 179 | /** |
| 180 | * Legacy get address. |
| 181 | */ |
| 182 | function get_address() { |
| 183 | wc_deprecated_function( 'WC_Customer::get_address', '3.0', 'WC_Customer::get_billing_address_1' ); |
| 184 | return $this->get_billing_address_1(); |
| 185 | } |
| 186 | |
| 187 | /** |
| 188 | * Legacy get address 2. |
| 189 | */ |
| 190 | function get_address_2() { |
| 191 | wc_deprecated_function( 'WC_Customer::get_address_2', '3.0', 'WC_Customer::get_billing_address_2' ); |
| 192 | return $this->get_billing_address_2(); |
| 193 | } |
| 194 | |
| 195 | /** |
| 196 | * Legacy get country. |
| 197 | */ |
| 198 | function get_country() { |
| 199 | wc_deprecated_function( 'WC_Customer::get_country', '3.0', 'WC_Customer::get_billing_country' ); |
| 200 | return $this->get_billing_country(); |
| 201 | } |
| 202 | |
| 203 | /** |
| 204 | * Legacy get state. |
| 205 | */ |
| 206 | function get_state() { |
| 207 | wc_deprecated_function( 'WC_Customer::get_state', '3.0', 'WC_Customer::get_billing_state' ); |
| 208 | return $this->get_billing_state(); |
| 209 | } |
| 210 | |
| 211 | /** |
| 212 | * Legacy get postcode. |
| 213 | */ |
| 214 | function get_postcode() { |
| 215 | wc_deprecated_function( 'WC_Customer::get_postcode', '3.0', 'WC_Customer::get_billing_postcode' ); |
| 216 | return $this->get_billing_postcode(); |
| 217 | } |
| 218 | |
| 219 | /** |
| 220 | * Legacy get city. |
| 221 | */ |
| 222 | function get_city() { |
| 223 | wc_deprecated_function( 'WC_Customer::get_city', '3.0', 'WC_Customer::get_billing_city' ); |
| 224 | return $this->get_billing_city(); |
| 225 | } |
| 226 | |
| 227 | /** |
| 228 | * Legacy set country. |
| 229 | * |
| 230 | * @param string $country |
| 231 | */ |
| 232 | function set_country( $country ) { |
| 233 | wc_deprecated_function( 'WC_Customer::set_country', '3.0', 'WC_Customer::set_billing_country' ); |
| 234 | $this->set_billing_country( $country ); |
| 235 | } |
| 236 | |
| 237 | /** |
| 238 | * Legacy set state. |
| 239 | * |
| 240 | * @param string $state |
| 241 | */ |
| 242 | function set_state( $state ) { |
| 243 | wc_deprecated_function( 'WC_Customer::set_state', '3.0', 'WC_Customer::set_billing_state' ); |
| 244 | $this->set_billing_state( $state ); |
| 245 | } |
| 246 | |
| 247 | /** |
| 248 | * Legacy set postcode. |
| 249 | * |
| 250 | * @param string $postcode |
| 251 | */ |
| 252 | function set_postcode( $postcode ) { |
| 253 | wc_deprecated_function( 'WC_Customer::set_postcode', '3.0', 'WC_Customer::set_billing_postcode' ); |
| 254 | $this->set_billing_postcode( $postcode ); |
| 255 | } |
| 256 | |
| 257 | /** |
| 258 | * Legacy set city. |
| 259 | * |
| 260 | * @param string $city |
| 261 | */ |
| 262 | function set_city( $city ) { |
| 263 | wc_deprecated_function( 'WC_Customer::set_city', '3.0', 'WC_Customer::set_billing_city' ); |
| 264 | $this->set_billing_city( $city ); |
| 265 | } |
| 266 | |
| 267 | /** |
| 268 | * Legacy set address. |
| 269 | * |
| 270 | * @param string $address |
| 271 | */ |
| 272 | function set_address( $address ) { |
| 273 | wc_deprecated_function( 'WC_Customer::set_address', '3.0', 'WC_Customer::set_billing_address' ); |
| 274 | $this->set_billing_address( $address ); |
| 275 | } |
| 276 | |
| 277 | /** |
| 278 | * Legacy set address. |
| 279 | * |
| 280 | * @param string $address |
| 281 | */ |
| 282 | function set_address_2( $address ) { |
| 283 | wc_deprecated_function( 'WC_Customer::set_address_2', '3.0', 'WC_Customer::set_billing_address_2' ); |
| 284 | $this->set_billing_address_2( $address ); |
| 285 | } |
| 286 | } |
| 287 |