Don't save to the database if we are working with sessions, save to the session when save() is called instead.
This commit is contained in:
parent
1bc9da3e91
commit
f4353f6aa9
|
@ -1012,10 +1012,16 @@ class WC_Customer extends WC_Legacy_Customer {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Save data (either create or update depending on if we are working on an existing customer).
|
* Save data. Create when creating a new user/class, update when editing
|
||||||
|
* an existing user, and save session when working on a logged out guest
|
||||||
|
* session.
|
||||||
* @since 2.7.0
|
* @since 2.7.0
|
||||||
*/
|
*/
|
||||||
public function save() {
|
public function save() {
|
||||||
|
if ( $this->_from_session && ! $this->_is_user ) {
|
||||||
|
$this->save_session_if_changed();
|
||||||
|
return;
|
||||||
|
}
|
||||||
if ( ! $this->_is_user ) {
|
if ( ! $this->_is_user ) {
|
||||||
$this->create();
|
$this->create();
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -416,6 +416,15 @@ class CustomerCRUD extends \WC_Unit_Test_Case {
|
||||||
$session = new \WC_Customer();
|
$session = new \WC_Customer();
|
||||||
$session->load_session();
|
$session->load_session();
|
||||||
$this->assertEquals( '124 South Street', $session->get_billing_address() );
|
$this->assertEquals( '124 South Street', $session->get_billing_address() );
|
||||||
|
|
||||||
|
$session = new \WC_Customer();
|
||||||
|
$session->load_session();
|
||||||
|
$session->set_billing_postcode( '32191' );
|
||||||
|
$session->save();
|
||||||
|
|
||||||
|
// should still be session ID, not a created row, since we are working with guests/sessions
|
||||||
|
$this->assertFalse( is_numeric( $session->get_id() ) );
|
||||||
|
$this->assertEquals( '32191' , $session->get_billing_postcode() );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue