0

I'm have a code show another product was seen in single product page.
my idea : save id of posts to array by session:
Then using loop or foreach to show title, img, link ...etc...
MY CODE

session_start();

    $_SESSION['id'] = get_the_ID();
     $cart = array (
        'id' => $_SESSION['id'],
    );

    $_SESSION['cart'][] = $cart; // array id

But, when user closed browser. all data not save.
And i want convert session to Cookie to save for one month. How to change for the right ways.
Please help to the idea for this Solution .

Thankyou all.

1 Answers1

1

if you want to change default session timeout, look here

But i would suggest to use a cookie instead: to set a cookie use the setcookie function, and do something like that:

 setcookie('cart', $cart ,mktime().time()+60*60*24*30);

It would set a cookie with your cart, and set the expire time to 30 days

Riccardo Bonafede
  • 610
  • 1
  • 9
  • 17