1

I am allowing non-logged-in customers to order to my website with the code below:

global $woocommerce;
if(empty($woocommerce->session->data)){
   $woocommerce->session->set_customer_session_cookie(true);
}

I want to destroy the session after an order has been made because all non-logged-in customers share the same session cookie and this can flood the cart.

function wc_destroy_customer_session() {
 global $woocommerce;
 $woocommerce->session->destroy_session();
}

add_action('woocommerce_thankyou', 'wc_destroy_customer_session', 10, 1);

The code above still does not destroy the wp_woocommerce_session_random_hash

Do you know how to make the destroy_session work? Thanks

Woocommerce Documentation:http://woocommerce.wp-a2z.org/oik_api/wc_session_handlerdestroy_session/

LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399
redshot
  • 2,930
  • 3
  • 31
  • 68
  • 1
    May be this can help you. https://stackoverflow.com/questions/38546354/woocommerce-cookies-and-sessions-get-the-current-products-in-cart – zipkundan Oct 19 '18 at 08:27

0 Answers0