TransWikia.com

Disable woocommerce cookies and delete cart data automatically

WordPress Development Asked by Usman Khan on December 26, 2020

I have a woocommerce website for some reasons I want to disable the cookies that saves the cart data if user closes his browser and come back to website after like an hour or 4 hours the cart needs to be empty I don’t want his/ her data to be saved to woocoomerce cart. Please help me out with the solution for this as I searched alot on google but no solution is available for this.

This is the code I used

add_filter('wc_session_expiring', 'so_26545001_filter_session_expiring' );

function so_26545001_filter_session_expiring($seconds) {
    return 60 * 60 * 23; // 23 hours
}

add_filter('wc_session_expiration', 'so_26545001_filter_session_expired' );

function so_26545001_filter_session_expired($seconds) {
    return 60 * 60 * 24; // 24 hours
}

but after adding this I can still see the items in the cart which had been added days ago

Thank You

One Answer

Your code is expiring the session after 24 hours. You need to change your return value to reflect the number of hours (commented in the example below):

add_filter('wc_session_expiring', 'so_26545001_filter_session_expiring' );

function so_26545001_filter_session_expiring($seconds) {
    return 60 * 60 * 1; // Change "1" to the number of hours: 1 for 1 hour, 4 for 4 hours, etc.
}

add_filter('wc_session_expiration', 'so_26545001_filter_session_expired' );

function so_26545001_filter_session_expired($seconds) {
    return 60 * 60 * 1; // Change "1" to the number of hours: 1 for 1 hour, 4 for 4 hours, etc.
}

Answered by butlerblog on December 26, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP