2016-03-08 21:44:28 +00:00
|
|
|
<?php
|
|
|
|
if ( ! defined( 'ABSPATH' ) ) {
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Legacy Customer.
|
|
|
|
*
|
2017-03-15 16:36:53 +00:00
|
|
|
* @version 3.0.0
|
2020-08-05 16:36:24 +00:00
|
|
|
* @package WooCommerce\Classes
|
2016-03-08 21:44:28 +00:00
|
|
|
* @category Class
|
|
|
|
* @author WooThemes
|
|
|
|
*/
|
2016-03-17 17:35:25 +00:00
|
|
|
abstract class WC_Legacy_Customer extends WC_Data {
|
2016-03-08 21:44:28 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* __isset legacy.
|
|
|
|
* @param mixed $key
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function __isset( $key ) {
|
|
|
|
$legacy_keys = array(
|
2016-09-01 10:46:05 +00:00
|
|
|
'id',
|
2016-08-27 03:04:10 +00:00
|
|
|
'country',
|
|
|
|
'state',
|
2016-09-01 20:50:14 +00:00
|
|
|
'postcode',
|
2016-08-27 03:04:10 +00:00
|
|
|
'city',
|
|
|
|
'address_1',
|
|
|
|
'address',
|
|
|
|
'address_2',
|
|
|
|
'shipping_country',
|
|
|
|
'shipping_state',
|
|
|
|
'shipping_postcode',
|
|
|
|
'shipping_city',
|
|
|
|
'shipping_address_1',
|
|
|
|
'shipping_address',
|
|
|
|
'shipping_address_2',
|
|
|
|
'is_vat_exempt',
|
|
|
|
'calculated_shipping',
|
2016-03-08 21:44:28 +00:00
|
|
|
);
|
|
|
|
$key = $this->filter_legacy_key( $key );
|
|
|
|
return in_array( $key, $legacy_keys );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* __get function.
|
|
|
|
* @param string $key
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function __get( $key ) {
|
2017-03-15 16:36:53 +00:00
|
|
|
wc_doing_it_wrong( $key, 'Customer properties should not be accessed directly.', '3.0' );
|
2016-03-08 21:44:28 +00:00
|
|
|
$key = $this->filter_legacy_key( $key );
|
2016-08-27 02:46:40 +00:00
|
|
|
if ( in_array( $key, array( 'country', 'state', 'postcode', 'city', 'address_1', 'address', 'address_2' ) ) ) {
|
2016-03-17 20:26:33 +00:00
|
|
|
$key = 'billing_' . $key;
|
|
|
|
}
|
2016-08-31 14:43:34 +00:00
|
|
|
return is_callable( array( $this, "get_{$key}" ) ) ? $this->{"get_{$key}"}() : '';
|
2016-03-08 21:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* __set function.
|
2017-05-15 11:50:52 +00:00
|
|
|
*
|
|
|
|
* @param string $key
|
|
|
|
* @param mixed $value
|
2016-03-08 21:44:28 +00:00
|
|
|
*/
|
|
|
|
public function __set( $key, $value ) {
|
2017-03-15 16:36:53 +00:00
|
|
|
wc_doing_it_wrong( $key, 'Customer properties should not be set directly.', '3.0' );
|
2016-03-08 21:44:28 +00:00
|
|
|
$key = $this->filter_legacy_key( $key );
|
2016-08-31 12:25:13 +00:00
|
|
|
|
2016-08-31 14:43:34 +00:00
|
|
|
if ( is_callable( array( $this, "set_{$key}" ) ) ) {
|
2016-08-31 12:25:13 +00:00
|
|
|
$this->{"set_{$key}"}( $value );
|
|
|
|
}
|
2016-03-08 21:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Address and shipping_address are aliased, so we want to get the 'real' key name.
|
|
|
|
* For all other keys, we can just return it.
|
2017-03-15 16:36:53 +00:00
|
|
|
* @since 3.0.0
|
2016-03-08 21:44:28 +00:00
|
|
|
* @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';
|
|
|
|
}
|
2016-03-17 20:26:33 +00:00
|
|
|
|
2016-03-08 21:44:28 +00:00
|
|
|
return $key;
|
|
|
|
}
|
|
|
|
|
2016-08-31 12:25:13 +00:00
|
|
|
/**
|
|
|
|
* 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 );
|
|
|
|
}
|
|
|
|
|
2016-03-09 20:49:02 +00:00
|
|
|
/**
|
|
|
|
* Get default country for a customer.
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function get_default_country() {
|
2017-03-15 16:36:53 +00:00
|
|
|
wc_deprecated_function( 'WC_Customer::get_default_country', '3.0', 'wc_get_customer_default_location' );
|
2016-03-09 20:49:02 +00:00
|
|
|
$default = wc_get_customer_default_location();
|
|
|
|
return $default['country'];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get default state for a customer.
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function get_default_state() {
|
2017-03-15 16:36:53 +00:00
|
|
|
wc_deprecated_function( 'WC_Customer::get_default_state', '3.0', 'wc_get_customer_default_location' );
|
2016-03-09 20:49:02 +00:00
|
|
|
$default = wc_get_customer_default_location();
|
|
|
|
return $default['state'];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set customer address to match shop base address.
|
|
|
|
*/
|
|
|
|
public function set_to_base() {
|
2017-03-15 16:36:53 +00:00
|
|
|
wc_deprecated_function( 'WC_Customer::set_to_base', '3.0', 'WC_Customer::set_billing_address_to_base' );
|
2016-03-17 20:28:40 +00:00
|
|
|
$this->set_billing_address_to_base();
|
2016-03-09 20:49:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set customer shipping address to base address.
|
|
|
|
*/
|
|
|
|
public function set_shipping_to_base() {
|
2017-03-15 16:36:53 +00:00
|
|
|
wc_deprecated_function( 'WC_Customer::set_shipping_to_base', '3.0', 'WC_Customer::set_shipping_address_to_base' );
|
2016-03-09 20:49:02 +00:00
|
|
|
$this->set_shipping_address_to_base();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Calculated shipping.
|
|
|
|
* @param boolean $calculated
|
|
|
|
*/
|
|
|
|
public function calculated_shipping( $calculated = true ) {
|
2017-03-15 16:36:53 +00:00
|
|
|
wc_deprecated_function( 'WC_Customer::calculated_shipping', '3.0', 'WC_Customer::set_calculated_shipping' );
|
2016-03-09 20:49:02 +00:00
|
|
|
$this->set_calculated_shipping( $calculated );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set default data for a customer.
|
|
|
|
*/
|
|
|
|
public function set_default_data() {
|
2017-03-15 16:36:53 +00:00
|
|
|
wc_deprecated_function( 'WC_Customer::set_default_data', '3.0' );
|
2016-03-09 20:49:02 +00:00
|
|
|
}
|
|
|
|
|
2016-11-14 18:18:08 +00:00
|
|
|
/**
|
|
|
|
* Save data function.
|
|
|
|
*/
|
|
|
|
public function save_data() {
|
|
|
|
$this->save();
|
|
|
|
}
|
|
|
|
|
2016-03-09 20:49:02 +00:00
|
|
|
/**
|
|
|
|
* Is the user a paying customer?
|
2017-05-15 11:50:52 +00:00
|
|
|
*
|
|
|
|
* @param int $user_id
|
|
|
|
*
|
2016-03-09 20:49:02 +00:00
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
function is_paying_customer( $user_id = '' ) {
|
2017-03-15 16:36:53 +00:00
|
|
|
wc_deprecated_function( 'WC_Customer::is_paying_customer', '3.0', 'WC_Customer::get_is_paying_customer' );
|
2016-03-09 20:49:02 +00:00
|
|
|
if ( ! empty( $user_id ) ) {
|
|
|
|
$user_id = get_current_user_id();
|
|
|
|
}
|
|
|
|
return '1' === get_user_meta( $user_id, 'paying_customer', true );
|
|
|
|
}
|
|
|
|
|
2017-04-25 12:18:58 +00:00
|
|
|
/**
|
|
|
|
* Legacy get address.
|
|
|
|
*/
|
|
|
|
function get_address() {
|
|
|
|
wc_deprecated_function( 'WC_Customer::get_address', '3.0', 'WC_Customer::get_billing_address_1' );
|
|
|
|
return $this->get_billing_address_1();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Legacy get address 2.
|
|
|
|
*/
|
|
|
|
function get_address_2() {
|
|
|
|
wc_deprecated_function( 'WC_Customer::get_address_2', '3.0', 'WC_Customer::get_billing_address_2' );
|
|
|
|
return $this->get_billing_address_2();
|
|
|
|
}
|
|
|
|
|
2016-03-17 20:40:30 +00:00
|
|
|
/**
|
|
|
|
* Legacy get country.
|
|
|
|
*/
|
|
|
|
function get_country() {
|
2017-03-15 16:36:53 +00:00
|
|
|
wc_deprecated_function( 'WC_Customer::get_country', '3.0', 'WC_Customer::get_billing_country' );
|
2016-03-17 20:40:30 +00:00
|
|
|
return $this->get_billing_country();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Legacy get state.
|
|
|
|
*/
|
|
|
|
function get_state() {
|
2017-03-15 16:36:53 +00:00
|
|
|
wc_deprecated_function( 'WC_Customer::get_state', '3.0', 'WC_Customer::get_billing_state' );
|
2016-03-17 20:40:30 +00:00
|
|
|
return $this->get_billing_state();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Legacy get postcode.
|
|
|
|
*/
|
|
|
|
function get_postcode() {
|
2017-03-15 16:36:53 +00:00
|
|
|
wc_deprecated_function( 'WC_Customer::get_postcode', '3.0', 'WC_Customer::get_billing_postcode' );
|
2016-03-17 20:40:30 +00:00
|
|
|
return $this->get_billing_postcode();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Legacy get city.
|
|
|
|
*/
|
|
|
|
function get_city() {
|
2017-03-15 16:36:53 +00:00
|
|
|
wc_deprecated_function( 'WC_Customer::get_city', '3.0', 'WC_Customer::get_billing_city' );
|
2016-03-17 20:40:30 +00:00
|
|
|
return $this->get_billing_city();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Legacy set country.
|
2017-05-15 11:50:52 +00:00
|
|
|
*
|
|
|
|
* @param string $country
|
2016-03-17 20:40:30 +00:00
|
|
|
*/
|
|
|
|
function set_country( $country ) {
|
2017-03-15 16:36:53 +00:00
|
|
|
wc_deprecated_function( 'WC_Customer::set_country', '3.0', 'WC_Customer::set_billing_country' );
|
2016-03-17 20:40:30 +00:00
|
|
|
$this->set_billing_country( $country );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Legacy set state.
|
2017-05-15 11:50:52 +00:00
|
|
|
*
|
|
|
|
* @param string $state
|
2016-03-17 20:40:30 +00:00
|
|
|
*/
|
|
|
|
function set_state( $state ) {
|
2017-03-15 16:36:53 +00:00
|
|
|
wc_deprecated_function( 'WC_Customer::set_state', '3.0', 'WC_Customer::set_billing_state' );
|
2016-03-17 20:40:30 +00:00
|
|
|
$this->set_billing_state( $state );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Legacy set postcode.
|
2017-05-15 11:50:52 +00:00
|
|
|
*
|
|
|
|
* @param string $postcode
|
2016-03-17 20:40:30 +00:00
|
|
|
*/
|
|
|
|
function set_postcode( $postcode ) {
|
2017-03-15 16:36:53 +00:00
|
|
|
wc_deprecated_function( 'WC_Customer::set_postcode', '3.0', 'WC_Customer::set_billing_postcode' );
|
2016-03-17 20:40:30 +00:00
|
|
|
$this->set_billing_postcode( $postcode );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Legacy set city.
|
2017-05-15 11:50:52 +00:00
|
|
|
*
|
|
|
|
* @param string $city
|
2016-03-17 20:40:30 +00:00
|
|
|
*/
|
|
|
|
function set_city( $city ) {
|
2017-03-15 16:36:53 +00:00
|
|
|
wc_deprecated_function( 'WC_Customer::set_city', '3.0', 'WC_Customer::set_billing_city' );
|
2016-03-17 20:40:30 +00:00
|
|
|
$this->set_billing_city( $city );
|
|
|
|
}
|
|
|
|
|
2016-08-04 20:13:07 +00:00
|
|
|
/**
|
|
|
|
* Legacy set address.
|
2017-05-15 11:50:52 +00:00
|
|
|
*
|
|
|
|
* @param string $address
|
2016-08-04 20:13:07 +00:00
|
|
|
*/
|
|
|
|
function set_address( $address ) {
|
2017-03-15 16:36:53 +00:00
|
|
|
wc_deprecated_function( 'WC_Customer::set_address', '3.0', 'WC_Customer::set_billing_address' );
|
2016-08-04 20:13:07 +00:00
|
|
|
$this->set_billing_address( $address );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Legacy set address.
|
2017-05-15 11:50:52 +00:00
|
|
|
*
|
|
|
|
* @param string $address
|
2016-08-04 20:13:07 +00:00
|
|
|
*/
|
|
|
|
function set_address_2( $address ) {
|
2017-03-15 16:36:53 +00:00
|
|
|
wc_deprecated_function( 'WC_Customer::set_address_2', '3.0', 'WC_Customer::set_billing_address_2' );
|
2016-08-04 20:13:07 +00:00
|
|
|
$this->set_billing_address_2( $address );
|
|
|
|
}
|
2016-03-08 21:44:28 +00:00
|
|
|
}
|