Make API and CRUD use consistent keys and make use of data
This commit is contained in:
parent
b82415dfa3
commit
047242515d
|
@ -486,62 +486,35 @@ class WC_REST_Customers_Controller extends WC_REST_Controller {
|
|||
* @return WP_REST_Response $response Response data.
|
||||
*/
|
||||
public function prepare_item_for_response( $user_data, $request ) {
|
||||
$customer = new WC_Customer( $user_data->ID );
|
||||
$last_order_data = $customer->get_last_order();
|
||||
$last_order = null;
|
||||
$customer = new WC_Customer( $user_data->ID );
|
||||
$data = $customer->get_data();
|
||||
$format_date = array( 'date_created', 'date_modified' );
|
||||
|
||||
if ( $last_order_data ) {
|
||||
$last_order = array(
|
||||
// Format date values.
|
||||
foreach ( $format_date as $key ) {
|
||||
$data[ $key ] = $data[ $key ] ? wc_rest_prepare_date_response( get_gmt_from_date( date( 'Y-m-d H:i:s', $data[ $key ] ) ) ) : null;
|
||||
}
|
||||
|
||||
// Remove unwanted CRUD data.
|
||||
unset( $data['role'] );
|
||||
|
||||
// Additional non-crud data.
|
||||
$data['last_order'] = null;
|
||||
$data['orders_count'] = $customer->get_order_count();
|
||||
$data['total_spent'] = $customer->get_total_spent();
|
||||
$data['avatar_url'] = $customer->get_avatar_url();
|
||||
|
||||
if ( $last_order_data = $customer->get_last_order() ) {
|
||||
$data['last_order'] = array(
|
||||
'id' => $last_order_data->get_id(),
|
||||
'date' => wc_rest_prepare_date_response( $last_order_data->get_date_created() ),
|
||||
);
|
||||
}
|
||||
|
||||
$data = array(
|
||||
'id' => $customer->get_id(),
|
||||
'date_created' => wc_rest_prepare_date_response( date( 'Y-m-d H:i:s', $customer->get_date_created() ) ),
|
||||
'date_modified' => $customer->get_date_modified() ? wc_rest_prepare_date_response( date( 'Y-m-d H:i:s', $customer->get_date_modified() ) ) : null,
|
||||
'email' => $customer->get_email(),
|
||||
'first_name' => $customer->get_first_name(),
|
||||
'last_name' => $customer->get_last_name(),
|
||||
'username' => $customer->get_username(),
|
||||
'last_order' => $last_order,
|
||||
'orders_count' => $customer->get_order_count(),
|
||||
'total_spent' => $customer->get_total_spent(),
|
||||
'avatar_url' => $customer->get_avatar_url(),
|
||||
'billing' => array(
|
||||
'first_name' => $customer->get_billing_first_name(),
|
||||
'last_name' => $customer->get_billing_last_name(),
|
||||
'company' => $customer->get_billing_company(),
|
||||
'address_1' => $customer->get_billing_address_1(),
|
||||
'address_2' => $customer->get_billing_address_2(),
|
||||
'city' => $customer->get_billing_city(),
|
||||
'state' => $customer->get_billing_state(),
|
||||
'postcode' => $customer->get_billing_postcode(),
|
||||
'country' => $customer->get_billing_country(),
|
||||
'email' => $customer->get_billing_email(),
|
||||
'phone' => $customer->get_billing_phone(),
|
||||
),
|
||||
'shipping' => array(
|
||||
'first_name' => $customer->get_shipping_first_name(),
|
||||
'last_name' => $customer->get_shipping_last_name(),
|
||||
'company' => $customer->get_shipping_company(),
|
||||
'address_1' => $customer->get_shipping_address_1(),
|
||||
'address_2' => $customer->get_shipping_address_2(),
|
||||
'city' => $customer->get_shipping_city(),
|
||||
'state' => $customer->get_shipping_state(),
|
||||
'postcode' => $customer->get_shipping_postcode(),
|
||||
'country' => $customer->get_shipping_country(),
|
||||
),
|
||||
);
|
||||
|
||||
$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
|
||||
$data = $this->add_additional_fields_to_object( $data, $request );
|
||||
$data = $this->filter_response_by_context( $data, $context );
|
||||
|
||||
// Wrap the data in a response object.
|
||||
$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
|
||||
$data = $this->add_additional_fields_to_object( $data, $request );
|
||||
$data = $this->filter_response_by_context( $data, $context );
|
||||
$response = rest_ensure_response( $data );
|
||||
|
||||
$response->add_links( $this->prepare_links( $user_data ) );
|
||||
|
||||
/**
|
||||
|
|
|
@ -1562,7 +1562,7 @@ class WC_Cart {
|
|||
return false;
|
||||
|
||||
if ( 'yes' === get_option( 'woocommerce_shipping_cost_requires_address' ) ) {
|
||||
if ( ! WC()->customer->get_calculated_shipping() ) {
|
||||
if ( ! WC()->customer->has_calculated_shipping() ) {
|
||||
if ( ! WC()->customer->get_shipping_country() || ( ! WC()->customer->get_shipping_state() && ! WC()->customer->get_shipping_postcode() ) ) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -21,38 +21,39 @@ class WC_Customer extends WC_Legacy_Customer {
|
|||
* @var array
|
||||
*/
|
||||
protected $_data = array(
|
||||
'id' => 0,
|
||||
'email' => '',
|
||||
'first_name' => '',
|
||||
'last_name' => '',
|
||||
'role' => 'customer',
|
||||
'username' => '', // read only on existing users
|
||||
'password' => '', // write only
|
||||
'date_created' => '', // read only
|
||||
'date_modified' => '', // read only
|
||||
'billing_first_name' => '',
|
||||
'billing_last_name' => '',
|
||||
'billing_company' => '',
|
||||
'billing_phone' => '',
|
||||
'billing_email' => '',
|
||||
'billing_address_1' => '',
|
||||
'billing_address_2' => '',
|
||||
'billing_state' => '',
|
||||
'billing_postcode' => '',
|
||||
'billing_city' => '',
|
||||
'billing_country' => '',
|
||||
'shipping_first_name' => '',
|
||||
'shipping_last_name' => '',
|
||||
'shipping_company' => '',
|
||||
'shipping_postcode' => '',
|
||||
'shipping_city' => '',
|
||||
'shipping_address_1' => '',
|
||||
'shipping_address_2' => '',
|
||||
'shipping_state' => '',
|
||||
'shipping_country' => '',
|
||||
'is_paying_customer' => false,
|
||||
'is_vat_exempt' => false, // session only.
|
||||
'calculated_shipping' => false, // session only
|
||||
'id' => 0,
|
||||
'date_created' => '',
|
||||
'date_modified' => '',
|
||||
'email' => '',
|
||||
'first_name' => '',
|
||||
'last_name' => '',
|
||||
'role' => 'customer',
|
||||
'username' => '',
|
||||
'billing' => array(
|
||||
'first_name' => '',
|
||||
'last_name' => '',
|
||||
'company' => '',
|
||||
'address_1' => '',
|
||||
'address_2' => '',
|
||||
'city' => '',
|
||||
'state' => '',
|
||||
'postcode' => '',
|
||||
'country' => '',
|
||||
'email' => '',
|
||||
'phone' => '',
|
||||
),
|
||||
'shipping' => array(
|
||||
'first_name' => '',
|
||||
'last_name' => '',
|
||||
'company' => '',
|
||||
'address_1' => '',
|
||||
'address_2' => '',
|
||||
'city' => '',
|
||||
'state' => '',
|
||||
'postcode' => '',
|
||||
'country' => '',
|
||||
),
|
||||
'is_paying_customer' => false,
|
||||
);
|
||||
|
||||
/**
|
||||
|
@ -101,6 +102,24 @@ class WC_Customer extends WC_Legacy_Customer {
|
|||
*/
|
||||
protected $_is_session = false;
|
||||
|
||||
/**
|
||||
* Stores a password if this needs to be changed. Write-only and hidden from _data.
|
||||
* @var string
|
||||
*/
|
||||
protected $_password = '';
|
||||
|
||||
/**
|
||||
* Stores if user is VAT exempt for this session.
|
||||
* @var string
|
||||
*/
|
||||
protected $_is_vat_exempt = false;
|
||||
|
||||
/**
|
||||
* Stores if user has calculated shipping in this session.
|
||||
* @var string
|
||||
*/
|
||||
protected $_calculated_shipping = false;
|
||||
|
||||
/**
|
||||
* Load customer data based on how WC_Customer is called.
|
||||
*
|
||||
|
@ -262,6 +281,22 @@ class WC_Customer extends WC_Legacy_Customer {
|
|||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is customer VAT exempt?
|
||||
* @return bool
|
||||
*/
|
||||
public function is_vat_exempt() {
|
||||
return $this->get_is_vat_exempt();
|
||||
}
|
||||
|
||||
/**
|
||||
* Has calculated shipping?
|
||||
* @return bool
|
||||
*/
|
||||
public function has_calculated_shipping() {
|
||||
return $this->get_calculated_shipping();
|
||||
}
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Getters
|
||||
|
@ -364,7 +399,7 @@ class WC_Customer extends WC_Legacy_Customer {
|
|||
* @return string
|
||||
*/
|
||||
public function get_billing_first_name() {
|
||||
return $this->_data['billing_first_name'];
|
||||
return $this->_data['billing']['first_name'];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -372,7 +407,7 @@ class WC_Customer extends WC_Legacy_Customer {
|
|||
* @return string
|
||||
*/
|
||||
public function get_billing_last_name() {
|
||||
return $this->_data['billing_last_name'];
|
||||
return $this->_data['billing']['last_name'];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -380,7 +415,7 @@ class WC_Customer extends WC_Legacy_Customer {
|
|||
* @return string
|
||||
*/
|
||||
public function get_billing_company() {
|
||||
return $this->_data['billing_company'];
|
||||
return $this->_data['billing']['company'];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -388,7 +423,7 @@ class WC_Customer extends WC_Legacy_Customer {
|
|||
* @return string
|
||||
*/
|
||||
public function get_billing_phone() {
|
||||
return $this->_data['billing_phone'];
|
||||
return $this->_data['billing']['phone'];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -396,7 +431,7 @@ class WC_Customer extends WC_Legacy_Customer {
|
|||
* @return string
|
||||
*/
|
||||
public function get_billing_email() {
|
||||
return $this->_data['billing_email'];
|
||||
return $this->_data['billing']['email'];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -404,7 +439,7 @@ class WC_Customer extends WC_Legacy_Customer {
|
|||
* @return string
|
||||
*/
|
||||
public function get_billing_postcode() {
|
||||
return wc_format_postcode( $this->_data['billing_postcode'], $this->get_billing_country() );
|
||||
return wc_format_postcode( $this->_data['billing']['postcode'], $this->get_billing_country() );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -412,7 +447,7 @@ class WC_Customer extends WC_Legacy_Customer {
|
|||
* @return string
|
||||
*/
|
||||
public function get_billing_city() {
|
||||
return $this->_data['billing_city'];
|
||||
return $this->_data['billing']['city'];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -420,7 +455,7 @@ class WC_Customer extends WC_Legacy_Customer {
|
|||
* @return string
|
||||
*/
|
||||
public function get_billing_address() {
|
||||
return $this->_data['billing_address_1'];
|
||||
return $this->_data['billing']['address_1'];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -436,7 +471,7 @@ class WC_Customer extends WC_Legacy_Customer {
|
|||
* @return string
|
||||
*/
|
||||
public function get_billing_address_2() {
|
||||
return $this->_data['billing_address_2'];
|
||||
return $this->_data['billing']['address_2'];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -444,7 +479,7 @@ class WC_Customer extends WC_Legacy_Customer {
|
|||
* @return string
|
||||
*/
|
||||
public function get_billing_state() {
|
||||
return $this->_data['billing_state'];
|
||||
return $this->_data['billing']['state'];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -452,7 +487,7 @@ class WC_Customer extends WC_Legacy_Customer {
|
|||
* @return string
|
||||
*/
|
||||
public function get_billing_country() {
|
||||
return $this->_data['billing_country'];
|
||||
return $this->_data['billing']['country'];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -460,7 +495,7 @@ class WC_Customer extends WC_Legacy_Customer {
|
|||
* @return string
|
||||
*/
|
||||
public function get_shipping_first_name() {
|
||||
return $this->_data['shipping_first_name'];
|
||||
return $this->_data['shipping']['first_name'];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -468,7 +503,7 @@ class WC_Customer extends WC_Legacy_Customer {
|
|||
* @return string
|
||||
*/
|
||||
public function get_shipping_last_name() {
|
||||
return $this->_data['shipping_last_name'];
|
||||
return $this->_data['shipping']['last_name'];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -476,7 +511,7 @@ class WC_Customer extends WC_Legacy_Customer {
|
|||
* @return string
|
||||
*/
|
||||
public function get_shipping_company() {
|
||||
return $this->_data['shipping_company'];
|
||||
return $this->_data['shipping']['company'];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -484,7 +519,7 @@ class WC_Customer extends WC_Legacy_Customer {
|
|||
* @return string
|
||||
*/
|
||||
public function get_shipping_state() {
|
||||
return $this->_data['shipping_state'];
|
||||
return $this->_data['shipping']['state'];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -492,7 +527,7 @@ class WC_Customer extends WC_Legacy_Customer {
|
|||
* @return string
|
||||
*/
|
||||
public function get_shipping_country() {
|
||||
return $this->_data['shipping_country'];
|
||||
return $this->_data['shipping']['country'];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -500,7 +535,7 @@ class WC_Customer extends WC_Legacy_Customer {
|
|||
* @return string
|
||||
*/
|
||||
public function get_shipping_postcode() {
|
||||
return wc_format_postcode( $this->_data['shipping_postcode'], $this->get_shipping_country() );
|
||||
return wc_format_postcode( $this->_data['shipping']['postcode'], $this->get_shipping_country() );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -508,7 +543,7 @@ class WC_Customer extends WC_Legacy_Customer {
|
|||
* @return string
|
||||
*/
|
||||
public function get_shipping_city() {
|
||||
return $this->_data['shipping_city'];
|
||||
return $this->_data['shipping']['city'];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -516,7 +551,7 @@ class WC_Customer extends WC_Legacy_Customer {
|
|||
* @return string
|
||||
*/
|
||||
public function get_shipping_address() {
|
||||
return $this->_data['shipping_address_1'];
|
||||
return $this->_data['shipping']['address_1'];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -532,7 +567,7 @@ class WC_Customer extends WC_Legacy_Customer {
|
|||
* @return string
|
||||
*/
|
||||
public function get_shipping_address_2() {
|
||||
return $this->_data['shipping_address_2'];
|
||||
return $this->_data['shipping']['address_2'];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -541,7 +576,7 @@ class WC_Customer extends WC_Legacy_Customer {
|
|||
* @return bool
|
||||
*/
|
||||
public function get_is_vat_exempt() {
|
||||
return ( ! empty( $this->_data['is_vat_exempt'] ) ) ? true : false;
|
||||
return $this->_is_vat_exempt;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -549,7 +584,7 @@ class WC_Customer extends WC_Legacy_Customer {
|
|||
* @return bool
|
||||
*/
|
||||
public function get_calculated_shipping() {
|
||||
return ! empty( $this->_data['calculated_shipping'] );
|
||||
return $this->_calculated_shipping;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -689,7 +724,7 @@ class WC_Customer extends WC_Legacy_Customer {
|
|||
* @throws WC_Data_Exception
|
||||
*/
|
||||
public function set_password( $password ) {
|
||||
$this->_data['password'] = wc_clean( $password );
|
||||
$this->_password = wc_clean( $password );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -719,10 +754,10 @@ class WC_Customer extends WC_Legacy_Customer {
|
|||
*/
|
||||
public function set_billing_address_to_base() {
|
||||
$base = wc_get_customer_default_location();
|
||||
$this->_data['billing_country'] = $base['country'];
|
||||
$this->_data['billing_state'] = $base['state'];
|
||||
$this->_data['billing_postcode'] = '';
|
||||
$this->_data['billing_city'] = '';
|
||||
$this->_data['billing']['country'] = $base['country'];
|
||||
$this->_data['billing']['state'] = $base['state'];
|
||||
$this->_data['billing']['postcode'] = '';
|
||||
$this->_data['billing']['city'] = '';
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -732,10 +767,10 @@ class WC_Customer extends WC_Legacy_Customer {
|
|||
*/
|
||||
public function set_shipping_address_to_base() {
|
||||
$base = wc_get_customer_default_location();
|
||||
$this->_data['shipping_country'] = $base['country'];
|
||||
$this->_data['shipping_state'] = $base['state'];
|
||||
$this->_data['shipping_postcode'] = '';
|
||||
$this->_data['shipping_city'] = '';
|
||||
$this->_data['shipping']['country'] = $base['country'];
|
||||
$this->_data['shipping']['state'] = $base['state'];
|
||||
$this->_data['shipping']['postcode'] = '';
|
||||
$this->_data['shipping']['city'] = '';
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -747,10 +782,10 @@ class WC_Customer extends WC_Legacy_Customer {
|
|||
* @throws WC_Data_Exception
|
||||
*/
|
||||
public function set_shipping_location( $country, $state = '', $postcode = '', $city = '' ) {
|
||||
$this->_data['shipping_country'] = $country;
|
||||
$this->_data['shipping_state'] = $state;
|
||||
$this->_data['shipping_postcode'] = $postcode;
|
||||
$this->_data['shipping_city'] = $city;
|
||||
$this->_data['shipping']['country'] = $country;
|
||||
$this->_data['shipping']['state'] = $state;
|
||||
$this->_data['shipping']['postcode'] = $postcode;
|
||||
$this->_data['shipping']['city'] = $city;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -762,10 +797,10 @@ class WC_Customer extends WC_Legacy_Customer {
|
|||
* @throws WC_Data_Exception
|
||||
*/
|
||||
public function set_billing_location( $country, $state, $postcode = '', $city = '' ) {
|
||||
$this->_data['billing_country'] = $country;
|
||||
$this->_data['billing_state'] = $state;
|
||||
$this->_data['billing_postcode'] = $postcode;
|
||||
$this->_data['billing_city'] = $city;
|
||||
$this->_data['billing']['country'] = $country;
|
||||
$this->_data['billing']['state'] = $state;
|
||||
$this->_data['billing']['postcode'] = $postcode;
|
||||
$this->_data['billing']['city'] = $city;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -774,7 +809,7 @@ class WC_Customer extends WC_Legacy_Customer {
|
|||
* @throws WC_Data_Exception
|
||||
*/
|
||||
public function set_billing_first_name( $value ) {
|
||||
$this->_data['billing_first_name'] = $value;
|
||||
$this->_data['billing']['first_name'] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -783,7 +818,7 @@ class WC_Customer extends WC_Legacy_Customer {
|
|||
* @throws WC_Data_Exception
|
||||
*/
|
||||
public function set_billing_last_name( $value ) {
|
||||
$this->_data['billing_last_name'] = $value;
|
||||
$this->_data['billing']['last_name'] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -792,7 +827,7 @@ class WC_Customer extends WC_Legacy_Customer {
|
|||
* @throws WC_Data_Exception
|
||||
*/
|
||||
public function set_billing_company( $value ) {
|
||||
$this->_data['billing_company'] = $value;
|
||||
$this->_data['billing']['company'] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -801,7 +836,7 @@ class WC_Customer extends WC_Legacy_Customer {
|
|||
* @throws WC_Data_Exception
|
||||
*/
|
||||
public function set_billing_phone( $value ) {
|
||||
$this->_data['billing_phone'] = $value;
|
||||
$this->_data['billing']['phone'] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -814,7 +849,7 @@ class WC_Customer extends WC_Legacy_Customer {
|
|||
if ( $value && ! is_email( $value ) ) {
|
||||
$this->error( 'customer_invalid_billing_email', __( 'Invalid billing email address', 'woocommerce' ) );
|
||||
}
|
||||
$this->_data['billing_email'] = sanitize_email( $value );
|
||||
$this->_data['billing']['email'] = sanitize_email( $value );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -823,7 +858,7 @@ class WC_Customer extends WC_Legacy_Customer {
|
|||
* @throws WC_Data_Exception
|
||||
*/
|
||||
public function set_billing_country( $country ) {
|
||||
$this->_data['billing_country'] = $country;
|
||||
$this->_data['billing']['country'] = $country;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -832,7 +867,7 @@ class WC_Customer extends WC_Legacy_Customer {
|
|||
* @throws WC_Data_Exception
|
||||
*/
|
||||
public function set_billing_state( $state ) {
|
||||
$this->_data['billing_state'] = $state;
|
||||
$this->_data['billing']['state'] = $state;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -841,7 +876,7 @@ class WC_Customer extends WC_Legacy_Customer {
|
|||
* @throws WC_Data_Exception
|
||||
*/
|
||||
public function set_billing_postcode( $postcode ) {
|
||||
$this->_data['billing_postcode'] = $postcode;
|
||||
$this->_data['billing']['postcode'] = $postcode;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -850,7 +885,7 @@ class WC_Customer extends WC_Legacy_Customer {
|
|||
* @throws WC_Data_Exception
|
||||
*/
|
||||
public function set_billing_city( $city ) {
|
||||
$this->_data['billing_city'] = $city;
|
||||
$this->_data['billing']['city'] = $city;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -859,7 +894,7 @@ class WC_Customer extends WC_Legacy_Customer {
|
|||
* @throws WC_Data_Exception
|
||||
*/
|
||||
public function set_billing_address( $address ) {
|
||||
$this->_data['billing_address_1'] = $address;
|
||||
$this->_data['billing']['address_1'] = $address;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -877,7 +912,7 @@ class WC_Customer extends WC_Legacy_Customer {
|
|||
* @throws WC_Data_Exception
|
||||
*/
|
||||
public function set_billing_address_2( $address ) {
|
||||
$this->_data['billing_address_2'] = $address;
|
||||
$this->_data['billing']['address_2'] = $address;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -886,7 +921,7 @@ class WC_Customer extends WC_Legacy_Customer {
|
|||
* @throws WC_Data_Exception
|
||||
*/
|
||||
public function set_shipping_first_name( $first_name ) {
|
||||
$this->_data['shipping_first_name'] = $first_name;
|
||||
$this->_data['shipping']['first_name'] = $first_name;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -895,7 +930,7 @@ class WC_Customer extends WC_Legacy_Customer {
|
|||
* @throws WC_Data_Exception
|
||||
*/
|
||||
public function set_shipping_last_name( $last_name ) {
|
||||
$this->_data['shipping_last_name'] = $last_name;
|
||||
$this->_data['shipping']['last_name'] = $last_name;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -904,7 +939,7 @@ class WC_Customer extends WC_Legacy_Customer {
|
|||
* @throws WC_Data_Exception
|
||||
*/
|
||||
public function set_shipping_company( $company ) {
|
||||
$this->_data['shipping_company'] = $company;
|
||||
$this->_data['shipping']['company'] = $company;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -913,7 +948,7 @@ class WC_Customer extends WC_Legacy_Customer {
|
|||
* @throws WC_Data_Exception
|
||||
*/
|
||||
public function set_shipping_country( $country ) {
|
||||
$this->_data['shipping_country'] = $country;
|
||||
$this->_data['shipping']['country'] = $country;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -922,7 +957,7 @@ class WC_Customer extends WC_Legacy_Customer {
|
|||
* @throws WC_Data_Exception
|
||||
*/
|
||||
public function set_shipping_state( $state ) {
|
||||
$this->_data['shipping_state'] = $state;
|
||||
$this->_data['shipping']['state'] = $state;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -931,7 +966,7 @@ class WC_Customer extends WC_Legacy_Customer {
|
|||
* @throws WC_Data_Exception
|
||||
*/
|
||||
public function set_shipping_postcode( $postcode ) {
|
||||
$this->_data['shipping_postcode'] = $postcode;
|
||||
$this->_data['shipping']['postcode'] = $postcode;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -940,7 +975,7 @@ class WC_Customer extends WC_Legacy_Customer {
|
|||
* @throws WC_Data_Exception
|
||||
*/
|
||||
public function set_shipping_city( $city ) {
|
||||
$this->_data['shipping_city'] = $city;
|
||||
$this->_data['shipping']['city'] = $city;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -949,7 +984,7 @@ class WC_Customer extends WC_Legacy_Customer {
|
|||
* @throws WC_Data_Exception
|
||||
*/
|
||||
public function set_shipping_address( $address ) {
|
||||
$this->_data['shipping_address_1'] = $address;
|
||||
$this->_data['shipping']['address_1'] = $address;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -967,7 +1002,7 @@ class WC_Customer extends WC_Legacy_Customer {
|
|||
* @throws WC_Data_Exception
|
||||
*/
|
||||
public function set_shipping_address_2( $address ) {
|
||||
$this->_data['shipping_address_2'] = $address;
|
||||
$this->_data['shipping']['address_2'] = $address;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -976,7 +1011,7 @@ class WC_Customer extends WC_Legacy_Customer {
|
|||
* @throws WC_Data_Exception
|
||||
*/
|
||||
public function set_is_vat_exempt( $is_vat_exempt ) {
|
||||
$this->_data['is_vat_exempt'] = (bool) $is_vat_exempt;
|
||||
$this->_is_vat_exempt = (bool) $is_vat_exempt;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -985,7 +1020,7 @@ class WC_Customer extends WC_Legacy_Customer {
|
|||
* @throws WC_Data_Exception
|
||||
*/
|
||||
public function set_calculated_shipping( $calculated = true ) {
|
||||
$this->_data['calculated_shipping'] = (bool) $calculated;
|
||||
$this->_calculated_shipping = (bool) $calculated;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1013,7 +1048,7 @@ class WC_Customer extends WC_Legacy_Customer {
|
|||
* @since 2.7.0.
|
||||
*/
|
||||
public function create() {
|
||||
$customer_id = wc_create_new_customer( $this->get_email(), $this->get_username(), $this->_data['password'] );
|
||||
$customer_id = wc_create_new_customer( $this->get_email(), $this->get_username(), $this->_password );
|
||||
|
||||
if ( ! is_wp_error( $customer_id ) ) {
|
||||
$this->_data['id'] = $customer_id;
|
||||
|
@ -1089,8 +1124,6 @@ class WC_Customer extends WC_Legacy_Customer {
|
|||
'role' => ! empty ( $user_object->roles[0] ) ? $user_object->roles[0] : 'customer',
|
||||
) );
|
||||
$this->read_meta_data();
|
||||
|
||||
unset( $this->_data['password'] ); // password is write only, never ever read it
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1102,9 +1135,9 @@ class WC_Customer extends WC_Legacy_Customer {
|
|||
|
||||
wp_update_user( array( 'ID' => $customer_ID, 'user_email' => $this->get_email() ) );
|
||||
// Only update password if a new one was set with set_password
|
||||
if ( isset( $this->_data['password'] ) ) {
|
||||
wp_update_user( array( 'ID' => $customer_ID, 'user_pass' => $this->_data['password'] ) );
|
||||
unset( $this->_data['password'] );
|
||||
if ( ! empty( $this->_password ) ) {
|
||||
wp_update_user( array( 'ID' => $customer_ID, 'user_pass' => $this->_password ) );
|
||||
$this->_password = '';
|
||||
}
|
||||
|
||||
update_user_meta( $this->get_id(), 'billing_first_name', $this->get_billing_first_name() );
|
||||
|
|
|
@ -74,24 +74,6 @@ abstract class WC_Legacy_Customer extends WC_Data {
|
|||
return $key;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is customer VAT exempt?
|
||||
* @return bool
|
||||
*/
|
||||
public function is_vat_exempt() {
|
||||
_deprecated_function( 'WC_Customer::is_vat_exempt', '2.7', 'WC_Customer::get_is_vat_exempt' );
|
||||
return $this->get_is_vat_exempt();
|
||||
}
|
||||
|
||||
/**
|
||||
* Has calculated shipping?
|
||||
* @return bool
|
||||
*/
|
||||
public function has_calculated_shipping() {
|
||||
_deprecated_function( 'WC_Customer::has_calculated_shipping', '2.7', 'WC_Customer::get_calculated_shipping' );
|
||||
return $this->get_calculated_shipping();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get default country for a customer.
|
||||
* @return string
|
||||
|
|
|
@ -304,7 +304,7 @@ function wc_cart_totals_order_total_html() {
|
|||
|
||||
if ( ! empty( $tax_string_array ) ) {
|
||||
$taxable_address = WC()->customer->get_taxable_address();
|
||||
$estimated_text = WC()->customer->is_customer_outside_base() && ! WC()->customer->get_calculated_shipping()
|
||||
$estimated_text = WC()->customer->is_customer_outside_base() && ! WC()->customer->has_calculated_shipping()
|
||||
? sprintf( ' ' . __( 'estimated for %s', 'woocommerce' ), WC()->countries->estimated_for_prefix( $taxable_address[0] ) . WC()->countries->countries[ $taxable_address[0] ] )
|
||||
: '';
|
||||
$value .= '<small class="includes_tax">' . sprintf( __( '(includes %s)', 'woocommerce' ), implode( ', ', $tax_string_array ) . $estimated_text ) . '</small>';
|
||||
|
|
|
@ -44,7 +44,7 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|||
printf( '%3$s <input type="hidden" name="shipping_method[%1$d]" data-index="%1$d" id="shipping_method_%1$d" value="%2$s" class="shipping_method" />', $index, esc_attr( $method->id ), wc_cart_totals_shipping_method_label( $method ) );
|
||||
do_action( 'woocommerce_after_shipping_rate', $method, $index );
|
||||
?>
|
||||
<?php elseif ( ! WC()->customer->get_calculated_shipping() ) : ?>
|
||||
<?php elseif ( ! WC()->customer->has_calculated_shipping() ) : ?>
|
||||
<?php echo wpautop( __( 'Shipping costs will be calculated once you have provided your address.', 'woocommerce' ) ); ?>
|
||||
<?php else : ?>
|
||||
<?php echo apply_filters( is_cart() ? 'woocommerce_cart_no_shipping_available_html' : 'woocommerce_no_shipping_available_html', wpautop( __( 'There are no shipping methods available. Please double check your address, or contact us if you need any help.', 'woocommerce' ) ) ); ?>
|
||||
|
|
|
@ -21,7 +21,7 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|||
}
|
||||
|
||||
?>
|
||||
<div class="cart_totals <?php if ( WC()->customer->get_calculated_shipping() ) echo 'calculated_shipping'; ?>">
|
||||
<div class="cart_totals <?php if ( WC()->customer->has_calculated_shipping() ) echo 'calculated_shipping'; ?>">
|
||||
|
||||
<?php do_action( 'woocommerce_before_cart_totals' ); ?>
|
||||
|
||||
|
@ -67,7 +67,7 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|||
|
||||
<?php if ( wc_tax_enabled() && 'excl' === WC()->cart->tax_display_cart ) :
|
||||
$taxable_address = WC()->customer->get_taxable_address();
|
||||
$estimated_text = WC()->customer->is_customer_outside_base() && ! WC()->customer->get_calculated_shipping()
|
||||
$estimated_text = WC()->customer->is_customer_outside_base() && ! WC()->customer->has_calculated_shipping()
|
||||
? sprintf( ' <small>(' . __( 'estimated for %s', 'woocommerce' ) . ')</small>', WC()->countries->estimated_for_prefix( $taxable_address[0] ) . WC()->countries->countries[ $taxable_address[0] ] )
|
||||
: '';
|
||||
|
||||
|
|
|
@ -149,17 +149,17 @@ class WC_Tests_CustomerCRUD extends WC_Unit_Test_Case {
|
|||
$this->assertEquals( $customer->get_shipping_address(), $customer->shipping_address_1 );
|
||||
$this->assertEquals( $customer->get_shipping_address_2(), $customer->shipping_address_2 );
|
||||
$this->assertEquals( $customer->get_is_vat_exempt(), $customer->is_vat_exempt );
|
||||
$this->assertEquals( $customer->get_calculated_shipping(), $customer->calculated_shipping );
|
||||
$this->assertEquals( $customer->has_calculated_shipping(), $customer->calculated_shipping );
|
||||
|
||||
// Functions
|
||||
$this->assertEquals( $customer->get_is_vat_exempt(), $customer->is_vat_exempt() );
|
||||
$this->assertEquals( $customer->get_calculated_shipping(), $customer->has_calculated_shipping() );
|
||||
$this->assertEquals( $customer->has_calculated_shipping(), $customer->has_calculated_shipping() );
|
||||
$default = wc_get_customer_default_location();
|
||||
$this->assertEquals( $default['country'], $customer->get_default_country() );
|
||||
$this->assertEquals( $default['state'], $customer->get_default_state() );
|
||||
$this->assertFalse( $customer->get_calculated_shipping() );
|
||||
$this->assertFalse( $customer->has_calculated_shipping() );
|
||||
$customer->calculated_shipping( true );
|
||||
$this->assertTrue( $customer->get_calculated_shipping() );
|
||||
$this->assertTrue( $customer->has_calculated_shipping() );
|
||||
$this->assertEquals( $customer->get_is_paying_customer(), $customer->is_paying_customer() );
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue