I have a some ajax in a wordpress plugin that does the following,
function hamper_builder_add_product() {
$product = wc_get_product($_POST['product_id']);
$_SESSION['hamper_products'][] = $_POST['product_id'];
die(print_r($_SESSION));
}
This gets fired when an add button is clicked and it should add the product id to the hamper_products array in the session, if a user clicks add for product 1, and then product 2 I would expect the response to look like this,
Array ( [hamper_products] => Array ( [0] => 1, [1] => 2 ) ),
however all that happens is the array has one index that gets overwritten, what am I doing wrong?
source https://stackoverflow.com/questions/68154013/session-getting-overwritten-instead-of-appended
Comments
Post a Comment