remove changed
This commit is contained in:
parent
62d0619b1a
commit
1595cc5767
|
@ -90,12 +90,6 @@ class WC_Customer extends WC_Legacy_Customer {
|
|||
*/
|
||||
protected $_meta_type = 'user';
|
||||
|
||||
/**
|
||||
* Was data changed in the database for this class?
|
||||
* @var boolean
|
||||
*/
|
||||
protected $_changed = false;
|
||||
|
||||
/**
|
||||
* If this is the customer session, this is true. When true, guest accounts will not be saved to the DB.
|
||||
* @var boolean
|
||||
|
@ -136,17 +130,7 @@ class WC_Customer extends WC_Legacy_Customer {
|
|||
if ( $is_session ) {
|
||||
$this->_is_session = true;
|
||||
$this->load_session();
|
||||
add_action( 'shutdown', array( $this, 'save_session_if_changed' ), 10 );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves customer information to the current session if any data changed.
|
||||
* @since 2.7.0
|
||||
*/
|
||||
public function save_session_if_changed() {
|
||||
if ( $this->_changed ) {
|
||||
$this->save_to_session();
|
||||
add_action( 'shutdown', array( $this, 'save_to_session' ), 10 );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1030,7 +1014,7 @@ class WC_Customer extends WC_Legacy_Customer {
|
|||
public function set_calculated_shipping( $calculated = true ) {
|
||||
$this->_calculated_shipping = (bool) $calculated;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| CRUD methods
|
||||
|
@ -1201,7 +1185,7 @@ class WC_Customer extends WC_Legacy_Customer {
|
|||
*/
|
||||
public function save() {
|
||||
if ( $this->_is_session ) {
|
||||
$this->save_session_if_changed();
|
||||
$this->save_to_session();
|
||||
} elseif ( ! $this->get_id() ) {
|
||||
$this->create();
|
||||
} else {
|
||||
|
@ -1222,7 +1206,9 @@ class WC_Customer extends WC_Legacy_Customer {
|
|||
}
|
||||
$data[ $session_key ] = $this->{"get_$function_key"}();
|
||||
}
|
||||
WC()->session->set( 'customer', $data );
|
||||
if ( $data !== WC()->session->get( 'customer' ) ) {
|
||||
WC()->session->set( 'customer', $data );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -39,7 +39,7 @@ abstract class WC_Legacy_Customer extends WC_Data {
|
|||
if ( in_array( $key, array( 'country', 'state', 'postcode' ,'city', 'address_1', 'address', 'address_2' ) ) ) {
|
||||
$key = 'billing_' . $key;
|
||||
}
|
||||
return isset( $this->_data[ $key ] ) ? $this->_data[ $key ] : '';
|
||||
return is_callable( $this, "get_{$key}" ) ? $this->{"get_{$key}"}() : '';
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -51,8 +51,10 @@ abstract class WC_Legacy_Customer extends WC_Data {
|
|||
public function __set( $key, $value ) {
|
||||
_doing_it_wrong( $key, 'Customer properties should not be set directly.', '2.7' );
|
||||
$key = $this->filter_legacy_key( $key );
|
||||
$this->_data[ $key ] = $value;
|
||||
$this->_changed = true;
|
||||
|
||||
if ( is_callable( $this, "set_{$key}" ) ) {
|
||||
$this->{"set_{$key}"}( $value );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -72,6 +74,19 @@ abstract class WC_Legacy_Customer extends WC_Data {
|
|||
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
|
||||
|
|
Loading…
Reference in New Issue