• Hi there

    Is there any way to limit the cart cookie life time? is there a filter where you set the cart expiration date?

    Can you do it through a cron task?

    TIA

    Dave

Viewing 6 replies - 1 through 6 (of 6 total)
  • Hi Dave

    I think the simplest and the best way to clear cart after specific amount of time will be by adding another variable to php session and update it on cart update.

    Just add following code at the end of functions.php file in Your theme. It will remove cart after 7 days of last update.

    add_action('jigoshop\cart\save', function() {
    	$_SESSION['cart_expiration_time'] = $time() + 60 * 60 * 24 * 7; // 7 days
    });
    
    add_action('init', function() {
    	if(isset($_SESSION['cart_expiration_time']) && $_SESSION['cart_expiration_time'] < time()) {
    		unset($_SESSION['jigoshop_cart_id'], $_SESSION['jigoshop_cart'], $_SESSION['cart_expiration_time']);
    	}
    });
    Thread Starter davidandrew

    (@davidandrew)

    Hi

    I tried adding the code and the Expires / Max-Age value stays the same

    1969-12-31T23:59:59.000Z

    I have to admit I am no cookie expert. Is there a chance you could provide the test environment you are using so I can replicate it:

    – Theme
    – WP version

    Thanks

    Dave

    Thread Starter davidandrew

    (@davidandrew)

    Hi

    I been looking through the ‘actions’ in your jigoshop ecommerce documentation. I can’t find any reference the the add_action tag ‘jigoshop\cart\save'[1]. Is it simply it hasn’t been added to the list?

    TIA

    Dave

    [1] https://www.jigoshop.com/documentation/jigoshop-ecommerce-actions/

    • This reply was modified 5 years, 9 months ago by davidandrew.
    Thread Starter davidandrew

    (@davidandrew)

    Could you also list which version of jigoshop-ecommerce you are using.

    Thanks

    Dave

    • This reply was modified 5 years, 9 months ago by davidandrew.
    • This reply was modified 5 years, 9 months ago by davidandrew.
    Thread Starter davidandrew

    (@davidandrew)

    Hi

    Apologies for the stream of updates. I have managed to test that the $_SESSION[‘cart_expiration_time’] is indeed being set and unset.

    What is not happening is the $_SESSION[‘jigoshop_cart_id’] and $_SESSION[‘jigoshop_cart’] are not being unset.

    Regards

    Dave

    Thread Starter davidandrew

    (@davidandrew)

    Hi There

    The solution that worked for me was this (your code put me in the right direction):

    add_action('jigoshop\cart\save', function() {
    	$_SESSION['cart_expiration_time'] = time() + (7200 * 1); // 2hrs
    });
    
    add_action('init', function() {
    	if(isset($_SESSION['cart_expiration_time']) && $_SESSION['cart_expiration_time'] < time()) {
    		unset($_SESSION['cart_expiration_time']);		
    		setcookie('jigoshop_cart_id', '',  time() - 3600, '/');
    		setcookie('jigoshop_session_key', '',  time() - 3600, '/');
    	}
    });

    Regards

    Dave

    • This reply was modified 5 years, 9 months ago by davidandrew.
    • This reply was modified 5 years, 9 months ago by davidandrew.
    • This reply was modified 5 years, 9 months ago by davidandrew.
    • This reply was modified 5 years, 9 months ago by davidandrew.
Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Any way to set cart expiration?’ is closed to new replies.