Clear sessions after ordering/on logout
This commit is contained in:
parent
0a3d9b3949
commit
41eab15b13
|
@ -69,6 +69,10 @@ class WC_Session_Handler extends WC_Session {
|
|||
add_action( 'woocommerce_set_cart_cookies', array( $this, 'set_customer_session_cookie' ), 10 );
|
||||
add_action( 'woocommerce_cleanup_sessions', array( $this, 'cleanup_sessions' ), 10 );
|
||||
add_action( 'shutdown', array( $this, 'save_data' ), 20 );
|
||||
add_action( 'clear_auth_cookie', array( $this, 'destroy_session' ) );
|
||||
if ( ! is_user_logged_in() ) {
|
||||
add_action( 'woocommerce_thankyou', array( $this, 'destroy_session' ) );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -180,6 +184,29 @@ class WC_Session_Handler extends WC_Session {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy all session data
|
||||
*/
|
||||
public function destroy_session() {
|
||||
// Clear cookie
|
||||
wc_setcookie( $this->_cookie, '', time() - YEAR_IN_SECONDS, apply_filters( 'wc_session_use_secure_cookie', false ) );
|
||||
|
||||
// Delete session
|
||||
$session_option = '_wc_session_' . $this->_customer_id;
|
||||
$session_expiry_option = '_wc_session_expires_' . $this->_customer_id;
|
||||
|
||||
delete_option( $session_option );
|
||||
delete_option( $session_expiry_option );
|
||||
|
||||
// Clear cart
|
||||
wc_empty_cart();
|
||||
|
||||
// Clear data
|
||||
$this->_data = array();
|
||||
$this->_dirty = false;
|
||||
$this->_customer_id = $this->generate_customer_id();
|
||||
}
|
||||
|
||||
/**
|
||||
* cleanup_sessions function.
|
||||
*
|
||||
|
|
|
@ -34,13 +34,11 @@ add_filter( 'woocommerce_add_to_cart_validation', 'wc_protected_product_add_to_c
|
|||
* @return void
|
||||
*/
|
||||
function wc_empty_cart() {
|
||||
if ( ! isset( WC()->cart ) || WC()->cart == '' )
|
||||
if ( ! isset( WC()->cart ) || WC()->cart == '' ) {
|
||||
WC()->cart = new WC_Cart();
|
||||
|
||||
}
|
||||
WC()->cart->empty_cart( false );
|
||||
}
|
||||
add_action( 'wp_logout', 'wc_empty_cart' );
|
||||
|
||||
|
||||
/**
|
||||
* Load the cart upon login
|
||||
|
|
|
@ -136,6 +136,7 @@ Yes you can! Join in on our [GitHub repository](http://github.com/woothemes/wooc
|
|||
* Tweak - Added the possibility to translate the edit-address endpoint slug.
|
||||
* Tweak - Removed all the_content filter in favor to wpautop() and do_shortcode().
|
||||
* Tweak - Send IPN email notifications to new order email.
|
||||
* Tweak - Clear and wipe session data on logout and end of checkout for guests.
|
||||
* Dev - Introduce `woocommerce_valid_order_statuses_for_payment_complete` filter.
|
||||
* Dev - Introduce `woocommerce_thankyou_order_received_text` filter.
|
||||
* Dev - Introduce `woocommerce_product_backorders_allowed` filter.
|
||||
|
|
Loading…
Reference in New Issue