WC_Legacy_Customer

Legacy Customer.

Defined (1)

The class is defined in the following location(s).

/includes/legacy/class-wc-legacy-customer.php  
  1. abstract class WC_Legacy_Customer extends WC_Data { 
  2.  
  3. /** 
  4. * __isset legacy. 
  5. * @param mixed $key 
  6. * @return bool 
  7. */ 
  8. public function __isset( $key ) { 
  9. $legacy_keys = array( 
  10. 'id',  
  11. 'country',  
  12. 'state',  
  13. 'postcode',  
  14. 'city',  
  15. 'address_1',  
  16. 'address',  
  17. 'address_2',  
  18. 'shipping_country',  
  19. 'shipping_state',  
  20. 'shipping_postcode',  
  21. 'shipping_city',  
  22. 'shipping_address_1',  
  23. 'shipping_address',  
  24. 'shipping_address_2',  
  25. 'is_vat_exempt',  
  26. 'calculated_shipping',  
  27. ); 
  28. $key = $this->filter_legacy_key( $key ); 
  29. return in_array( $key, $legacy_keys ); 
  30.  
  31. /** 
  32. * __get function. 
  33. * @param string $key 
  34. * @return string 
  35. */ 
  36. public function __get( $key ) { 
  37. wc_doing_it_wrong( $key, 'Customer properties should not be accessed directly.', '3.0' ); 
  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. return is_callable( array( $this, "get_{$key}" ) ) ? $this->{"get_{$key}"}() : ''; 
  42.  
  43. /** 
  44. * __set function. 
  45. * @param mixed $property 
  46. * @param mixed $key 
  47. */ 
  48. public function __set( $key, $value ) { 
  49. wc_doing_it_wrong( $key, 'Customer properties should not be set directly.', '3.0' ); 
  50. $key = $this->filter_legacy_key( $key ); 
  51.  
  52. if ( is_callable( array( $this, "set_{$key}" ) ) ) { 
  53. $this->{"set_{$key}"}( $value ); 
  54.  
  55. /** 
  56. * Address and shipping_address are aliased, so we want to get the 'real' key name. 
  57. * For all other keys, we can just return it. 
  58. * @since 3.0.0 
  59. * @param string $key 
  60. * @return string 
  61. */ 
  62. private function filter_legacy_key( $key ) { 
  63. if ( 'address' === $key ) { 
  64. $key = 'address_1'; 
  65. if ( 'shipping_address' === $key ) { 
  66. $key = 'shipping_address_1'; 
  67.  
  68. return $key; 
  69.  
  70. /** 
  71. * Sets session data for the location. 
  72. * @param string $country 
  73. * @param string $state 
  74. * @param string $postcode (default: '') 
  75. * @param string $city (default: '') 
  76. */ 
  77. public function set_location( $country, $state, $postcode = '', $city = '' ) { 
  78. $this->set_billing_location( $country, $state, $postcode, $city ); 
  79. $this->set_shipping_location( $country, $state, $postcode, $city ); 
  80.  
  81. /** 
  82. * Get default country for a customer. 
  83. * @return string 
  84. */ 
  85. public function get_default_country() { 
  86. wc_deprecated_function( 'WC_Customer::get_default_country', '3.0', 'wc_get_customer_default_location' ); 
  87. $default = wc_get_customer_default_location(); 
  88. return $default['country']; 
  89.  
  90. /** 
  91. * Get default state for a customer. 
  92. * @return string 
  93. */ 
  94. public function get_default_state() { 
  95. wc_deprecated_function( 'WC_Customer::get_default_state', '3.0', 'wc_get_customer_default_location' ); 
  96. $default = wc_get_customer_default_location(); 
  97. return $default['state']; 
  98.  
  99. /** 
  100. * Set customer address to match shop base address. 
  101. */ 
  102. public function set_to_base() { 
  103. wc_deprecated_function( 'WC_Customer::set_to_base', '3.0', 'WC_Customer::set_billing_address_to_base' ); 
  104. $this->set_billing_address_to_base(); 
  105.  
  106. /** 
  107. * Set customer shipping address to base address. 
  108. */ 
  109. public function set_shipping_to_base() { 
  110. wc_deprecated_function( 'WC_Customer::set_shipping_to_base', '3.0', 'WC_Customer::set_shipping_address_to_base' ); 
  111. $this->set_shipping_address_to_base(); 
  112.  
  113. /** 
  114. * Calculated shipping. 
  115. * @param boolean $calculated 
  116. */ 
  117. public function calculated_shipping( $calculated = true ) { 
  118. wc_deprecated_function( 'WC_Customer::calculated_shipping', '3.0', 'WC_Customer::set_calculated_shipping' ); 
  119. $this->set_calculated_shipping( $calculated ); 
  120.  
  121. /** 
  122. * Set default data for a customer. 
  123. */ 
  124. public function set_default_data() { 
  125. wc_deprecated_function( 'WC_Customer::set_default_data', '3.0' ); 
  126.  
  127. /** 
  128. * Save data function. 
  129. */ 
  130. public function save_data() { 
  131. $this->save(); 
  132.  
  133. /** 
  134. * Is the user a paying customer? 
  135. * @return bool 
  136. */ 
  137. function is_paying_customer( $user_id = '' ) { 
  138. wc_deprecated_function( 'WC_Customer::is_paying_customer', '3.0', 'WC_Customer::get_is_paying_customer' ); 
  139. if ( ! empty( $user_id ) ) { 
  140. $user_id = get_current_user_id(); 
  141. return '1' === get_user_meta( $user_id, 'paying_customer', true ); 
  142.  
  143. /** 
  144. * Legacy get address. 
  145. */ 
  146. function get_address() { 
  147. wc_deprecated_function( 'WC_Customer::get_address', '3.0', 'WC_Customer::get_billing_address_1' ); 
  148. return $this->get_billing_address_1(); 
  149.  
  150. /** 
  151. * Legacy get address 2. 
  152. */ 
  153. function get_address_2() { 
  154. wc_deprecated_function( 'WC_Customer::get_address_2', '3.0', 'WC_Customer::get_billing_address_2' ); 
  155. return $this->get_billing_address_2(); 
  156.  
  157. /** 
  158. * Legacy get country. 
  159. */ 
  160. function get_country() { 
  161. wc_deprecated_function( 'WC_Customer::get_country', '3.0', 'WC_Customer::get_billing_country' ); 
  162. return $this->get_billing_country(); 
  163.  
  164. /** 
  165. * Legacy get state. 
  166. */ 
  167. function get_state() { 
  168. wc_deprecated_function( 'WC_Customer::get_state', '3.0', 'WC_Customer::get_billing_state' ); 
  169. return $this->get_billing_state(); 
  170.  
  171. /** 
  172. * Legacy get postcode. 
  173. */ 
  174. function get_postcode() { 
  175. wc_deprecated_function( 'WC_Customer::get_postcode', '3.0', 'WC_Customer::get_billing_postcode' ); 
  176. return $this->get_billing_postcode(); 
  177.  
  178. /** 
  179. * Legacy get city. 
  180. */ 
  181. function get_city() { 
  182. wc_deprecated_function( 'WC_Customer::get_city', '3.0', 'WC_Customer::get_billing_city' ); 
  183. return $this->get_billing_city(); 
  184.  
  185. /** 
  186. * Legacy set country. 
  187. */ 
  188. function set_country( $country ) { 
  189. wc_deprecated_function( 'WC_Customer::set_country', '3.0', 'WC_Customer::set_billing_country' ); 
  190. $this->set_billing_country( $country ); 
  191.  
  192. /** 
  193. * Legacy set state. 
  194. */ 
  195. function set_state( $state ) { 
  196. wc_deprecated_function( 'WC_Customer::set_state', '3.0', 'WC_Customer::set_billing_state' ); 
  197. $this->set_billing_state( $state ); 
  198.  
  199. /** 
  200. * Legacy set postcode. 
  201. */ 
  202. function set_postcode( $postcode ) { 
  203. wc_deprecated_function( 'WC_Customer::set_postcode', '3.0', 'WC_Customer::set_billing_postcode' ); 
  204. $this->set_billing_postcode( $postcode ); 
  205.  
  206. /** 
  207. * Legacy set city. 
  208. */ 
  209. function set_city( $city ) { 
  210. wc_deprecated_function( 'WC_Customer::set_city', '3.0', 'WC_Customer::set_billing_city' ); 
  211. $this->set_billing_city( $city ); 
  212.  
  213. /** 
  214. * Legacy set address. 
  215. */ 
  216. function set_address( $address ) { 
  217. wc_deprecated_function( 'WC_Customer::set_address', '3.0', 'WC_Customer::set_billing_address' ); 
  218. $this->set_billing_address( $address ); 
  219.  
  220. /** 
  221. * Legacy set address. 
  222. */ 
  223. function set_address_2( $address ) { 
  224. wc_deprecated_function( 'WC_Customer::set_address_2', '3.0', 'WC_Customer::set_billing_address_2' ); 
  225. $this->set_billing_address_2( $address );