plugins - Disable woocommerce cookies and delete cart data automatically

admin2025-01-07  3

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

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

Share Improve this question edited Dec 24, 2020 at 18:22 butlerblog 5,0713 gold badges26 silver badges42 bronze badges asked Dec 21, 2020 at 17:54 Usman KhanUsman Khan 113 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

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.
}
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1736255692a301.html

最新回复(0)