filter_legacy_key( $key ); return in_array( $key, $legacy_keys ); } /** * __get function. * @param string $key * @return string */ public function __get( $key ) { _doing_it_wrong( $key, 'Customer properties should not be accessed directly.', '2.7' ); $key = $this->filter_legacy_key( $key ); if ( in_array( $key, array( 'country', 'state', 'postcode', 'city', 'address_1', 'address', 'address_2' ) ) ) { $key = 'billing_' . $key; } return is_callable( array( $this, "get_{$key}" ) ) ? $this->{"get_{$key}"}() : ''; } /** * __set function. * @param mixed $property * @param mixed $key */ public function __set( $key, $value ) { _doing_it_wrong( $key, 'Customer properties should not be set directly.', '2.7' ); $key = $this->filter_legacy_key( $key ); if ( is_callable( array( $this, "set_{$key}" ) ) ) { $this->{"set_{$key}"}( $value ); } } /** * Address and shipping_address are aliased, so we want to get the 'real' key name. * For all other keys, we can just return it. * @since 2.7.0 * @param string $key * @return string */ private function filter_legacy_key( $key ) { if ( 'address' === $key ) { $key = 'address_1'; } if ( 'shipping_address' === $key ) { $key = 'shipping_address_1'; } return $key; } /** * Sets session data for the location. * * @param string $country * @param string $state * @param string $postcode (default: '') * @param string $city (default: '') */ public function set_location( $country, $state, $postcode = '', $city = '' ) { $this->set_billing_location( $country, $state, $postcode, $city ); $this->set_shipping_location( $country, $state, $postcode, $city ); } /** * Get default country for a customer. * @return string */ public function get_default_country() { _deprecated_function( 'WC_Customer::get_default_country', '2.7', 'wc_get_customer_default_location' ); $default = wc_get_customer_default_location(); return $default['country']; } /** * Get default state for a customer. * @return string */ public function get_default_state() { _deprecated_function( 'WC_Customer::get_default_state', '2.7', 'wc_get_customer_default_location' ); $default = wc_get_customer_default_location(); return $default['state']; } /** * Set customer address to match shop base address. */ public function set_to_base() { _deprecated_function( 'WC_Customer::set_to_base', '2.7', 'WC_Customer::set_billing_address_to_base' ); $this->set_billing_address_to_base(); } /** * Set customer shipping address to base address. */ public function set_shipping_to_base() { _deprecated_function( 'WC_Customer::set_shipping_to_base', '2.7', 'WC_Customer::set_shipping_address_to_base' ); $this->set_shipping_address_to_base(); } /** * Calculated shipping. * @param boolean $calculated */ public function calculated_shipping( $calculated = true ) { _deprecated_function( 'WC_Customer::calculated_shipping', '2.7', 'WC_Customer::set_calculated_shipping' ); $this->set_calculated_shipping( $calculated ); } /** * Set default data for a customer. */ public function set_default_data() { _deprecated_function( 'WC_Customer::set_default_data', '2.7' ); } /** * Save data function. */ public function save_data() { $this->save(); } /** * Is the user a paying customer? * @return bool */ function is_paying_customer( $user_id = '' ) { _deprecated_function( 'WC_Customer::is_paying_customer', '2.7', 'WC_Customer::get_is_paying_customer' ); if ( ! empty( $user_id ) ) { $user_id = get_current_user_id(); } return '1' === get_user_meta( $user_id, 'paying_customer', true ); } /** * Legacy get country. */ function get_country() { _deprecated_function( 'WC_Customer::get_country', '2.7', 'WC_Customer::get_billing_country' ); return $this->get_billing_country(); } /** * Legacy get state. */ function get_state() { _deprecated_function( 'WC_Customer::get_state', '2.7', 'WC_Customer::get_billing_state' ); return $this->get_billing_state(); } /** * Legacy get postcode. */ function get_postcode() { _deprecated_function( 'WC_Customer::get_postcode', '2.7', 'WC_Customer::get_billing_postcode' ); return $this->get_billing_postcode(); } /** * Legacy get city. */ function get_city() { _deprecated_function( 'WC_Customer::get_city', '2.7', 'WC_Customer::get_billing_city' ); return $this->get_billing_city(); } /** * Legacy set country. */ function set_country( $country ) { _deprecated_function( 'WC_Customer::set_country', '2.7', 'WC_Customer::set_billing_country' ); $this->set_billing_country( $country ); } /** * Legacy set state. */ function set_state( $state ) { _deprecated_function( 'WC_Customer::set_state', '2.7', 'WC_Customer::set_billing_state' ); $this->set_billing_state( $state ); } /** * Legacy set postcode. */ function set_postcode( $postcode ) { _deprecated_function( 'WC_Customer::set_postcode', '2.7', 'WC_Customer::set_billing_postcode' ); $this->set_billing_postcode( $postcode ); } /** * Legacy set city. */ function set_city( $city ) { _deprecated_function( 'WC_Customer::set_city', '2.7', 'WC_Customer::set_billing_city' ); $this->set_billing_city( $city ); } /** * Legacy set address. */ function set_address( $address ) { _deprecated_function( 'WC_Customer::set_address', '2.7', 'WC_Customer::set_billing_address' ); $this->set_billing_address( $address ); } /** * Legacy set address. */ function set_address_2( $address ) { _deprecated_function( 'WC_Customer::set_address_2', '2.7', 'WC_Customer::set_billing_address_2' ); $this->set_billing_address_2( $address ); } }