'Deleting cookie wp_woocommerce_session_ for not logged users with PHP
My problem is I have woocommerce action addToCart() which verifies nonce from POST - if user is not logged if he chooses product first time nonce is verfied and everything works, but after that nonce can't be verifed, deleting wp_woocommerce_session cookie seems to fix this problem, but I dont want to delete it for logged users so I can't use JS for this, I tried using
WC()->session->forget_session() and WC()->session->destroy_session()
But this functions deletes all cookies like woocommerce_hash_cart and woocommerce_items_in_cart
if($_COOKIE) {
foreach ($_COOKIE as $key=>$val)
{
if(str_contains($key,"wp_woocommerce_session_")){
unset($_COOKIE[$key]);
wc_setcookie($key, '', time()-3600);
setcookie($key, '', time()-3600);
}
}
}
But sadly it doesn't work, do you have any idea how can i remove just this one Cookie?
Solution 1:[1]
Deleting all caching modules and adding if statement to ajax call which checks if nonce is not verifed if its true then reload window location with no cache works just fine :)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Magikstah |
