• Resolved samnait

    (@samnait)


    Hi, is it possible to set a date and time instead of per add item to cart execution?
    So instead of you have 1 hour 30 minutes to check out.
    It will be this…
    You have until 11 PM to check out your items. Then the count starts from when it was added to 11 PM then the items will return to stock if not checked out.

    Hope this makes sense. Thanks!

Viewing 11 replies - 1 through 11 (of 11 total)
  • Plugin Author James Golovich

    (@jamesgol)

    Yes you can definitely do this. The expiration time in the settings is passed through the PHP strtotime() function which can do some pretty fun stuff.

    • 5 minutes
    • 11pm
    • Tomorrow 11pm

    At the time the item is added to the cart that function is called so the time will always be relative to that moment.

    If you want to do more extensive configuration you can use the ‘wc_csr_expire_time’ filter to adjust the time.

    Thread Starter samnait

    (@samnait)

    hmmm I guess I’m a bit confused. How would I do this?
    I wanted to modify the one that you have now. where and how I would edit this?
    So just to be clear.
    If customer A added an item in the cart at 10:20pm
    And customer B added an item in the cart at 10:30pm
    Both customers will have no items in their cart at 11pm because it will be put back in the inventory.
    And wanted this to happen every day to trigger at 11pm

    Thanks a bunch.

    Plugin Author James Golovich

    (@jamesgol)

    I thought that just setting the time setting to ’11pm’ would work, but it occurred to me that after 11pm but before the next day starts the items added would expire immediately.

    So if you can use ’23:59:59′ as a time it should work (assuming someone doesn’t add an item at exactly the wrong time) otherwise you’ll have to create a function that hooks to the filter that checks if the current time is before 11pm then use todays 11pm, if it’s after 11pm then you use tomorrows 11pm

    Thread Starter samnait

    (@samnait)

    Wow thank you so much! It worked ??
    One last thing, because I already have a custom notification that says “if you don’t check out before 11 pm, you will lose the items in your cart”
    How would I remove
    Please check out within… time count down?
    Thanks again.

    Plugin Author James Golovich

    (@jamesgol)

    There is a setting labeled ‘Expire Countdown’ that you can set to ‘Never’ which will prevent the countdown from displaying

    Thread Starter samnait

    (@samnait)

    Okay found it and that did the trick.
    I don’t get the logic on the time to expire settings though.
    So this time…
    it is 12:50 PM system time so I set the backend as 23:00:00
    It says you have 3 hours and 9 minutes and sec.
    based on this sample do you know what the calculations be to have it expire at 11 pm?
    (what I would set the settings to have it expire at 11pm instead of 23:00:00)?

    Thanks again

    Plugin Author James Golovich

    (@jamesgol)

    If you want items to expire at 11pm you are going to have to do a bit of coding. Otherwise if someone adds an item after 11pm but before midnight the item will immediately expire since it is past 11pm for the current day.

    Thread Starter samnait

    (@samnait)

    hmm I worked on this for 4 hours and can’t get it at all.
    If you find a solution let me know. I’ll keep checking back.

    Thanks anyways.

    Plugin Author James Golovich

    (@jamesgol)

    You could use something like this. Written in the browser, so it’s untested but should be good enough to get you on your way

    
    add_filter('wc_csr_expire_time', 'jmg_expire_time', 10, 5);
    function jmg_expire_time( $time, $expire_time_text, $item, $key, $csr) {
         $now = time();
         if ($now > strtotime('11pm')) {
              $time = strtotime('tomorrow 11pm');
         } else {
              $time = strtotime('11pm');
         }
         return $time;
    
    }
    

    Add that to your child theme’s functions.php (or anywhere you add custom code) and you should be good to go. In the configuration I would set the expiration time to something like ’11PM’, it will be overridden by the filter but the text is used in the default ‘Append expiration time to pending order text’

    Thread Starter samnait

    (@samnait)

    Thank you for taking the time to do this. I will test right away and get back to you!

    Thread Starter samnait

    (@samnait)

    FLAWLESS! It worked! Thank you, Thank you.

    It gave me another 24 hours after it expired where before it would not let you reorder when it expired.
    So just to recap. And I think someone would find this plugin very useful.
    1. it clears all the sessions in the cart that has been abandoned.
    2. it will do it daily at a specified time you set and hide notification if you chose.
    3. combined with the link that I found on GitHub, it will identify which category you want this applied to so not all products will expire.
    4. It’s automated.
    I have searched everywhere and nobody has this not even close. They can only hide or expire products but it will not clear the carts in a certain category specified and put back in inventory with or without variables.
    On your next update for this should be implemented.

    Thanks again James
    ====
    add_filter(‘wc_csr_expire_time’, ‘jmg_expire_time’, 10, 5);
    function jmg_expire_time( $time, $expire_time_text, $item, $key, $csr) {
    $now = time();
    if ($now > strtotime(’22:45:00′)) {
    $time = strtotime(‘tomorrow 22:45:00′);
    } else {
    $time = strtotime(’22:45:00’);
    }
    return $time;

    }

    • This reply was modified 5 years, 10 months ago by samnait.
Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘selected date and time to expire’ is closed to new replies.