0.00  View Cart

Support WooCommerce Easy Booking [Resolved] Possibility to set 'First available date' in relation to current time

This topic contains 15 replies, has 2 voices, and was last updated by  hellopeterjensen 1 year, 5 months ago.

Viewing 15 posts - 1 through 15 (of 16 total)
  • Author
    Posts
  • #4449

    hellopeterjensen
    Participant

    Hi

    Is it possible to add an option for choosing a first available date in relation to the current time? For example, I want my customers to be able to put an order for tomorrow at 14:00/2pm latest. If they enter my shop after that time the first available date should be the day after tomorrow.

    Cheers
    Peter

    #4450

    Ashanna
    Plugin's author

    Hello,

    Yes, it’s possible. Please add this code to your theme’s functions.php:

    add_filter( 'easy_booking_product_first_available_date', 'set_date_to_next_day', 10, 2 );
    
    function set_date_to_next_day( $first_available_date, $product ) {
    
        $timezone = get_option( 'timezone_string' );
        date_default_timezone_set( $timezone );
    
        $time = date( 'H:i:s', strtotime( '14:00:00' ) );
        $timenow = date( 'H:i:s', strtotime( 'now' ) );
    
        if ( $timenow > $time ) {
            $first_available_date += 1;
        }
    
        return $first_available_date;
    
    }

    Regards,
    Natasha

    #4466

    hellopeterjensen
    Participant

    Thank you so much!

    #4469

    hellopeterjensen
    Participant

    Hi again Natasha

    Now the time is 15:03 where I am, and I can still choose tomorrow in the calendar.

    Have you got an idea why it doesn’t work?

    Best
    Peter

    #4472

    Ashanna
    Plugin's author

    Hello,

    Well it only adds one day to your first available date setting. So either you set “First available date” to 1 or you change line 12 in the code I gave you and set 2 instead of 1:

    add_filter( 'easy_booking_product_first_available_date', 'set_date_to_next_day', 10, 2 );
    
    function set_date_to_next_day( $first_available_date, $product ) {
    
        $timezone = get_option( 'timezone_string' );
        date_default_timezone_set( $timezone );
    
        $time = date( 'H:i:s', strtotime( '14:00:00' ) );
        $timenow = date( 'H:i:s', strtotime( 'now' ) );
    
        if ( $timenow > $time ) {
            $first_available_date += 2;
        }
    
        return $first_available_date;
    
    }

    Regards,
    Natasha

    #4473

    hellopeterjensen
    Participant

    Ahh okay. I thought it added the +1 day to my current settings. I’ll go ahead and change it. Thanks!

    #4475

    Ashanna
    Plugin's author

    It does, but if your current setting is 0, then it will be 1 (= tomorrow). If you want the day after tomorrow, you need 2 🙂

    I don’t know if I’m being clear!

    #4476

    hellopeterjensen
    Participant

    It was 1, so that’s why I didn’t understand. So at all times it should be tomorrow, but if the time is more than 14:00 it should be the day after tomorrow.

    I’ll try to change it to two in functions.php, but otherwise I don’t know.

    #4477

    hellopeterjensen
    Participant

    It still doesn’t work. It’s like the code you wrote me is not being executed…

    #4478

    Ashanna
    Plugin's author

    Where did you put the code? Which version of Easy Booking do you have?

    Do you have a link to your website?

    #4479

    hellopeterjensen
    Participant

    I put in the the functions.php before the last ?>.

    I’m using version 2.1.9.

    The website is mirabelle-bakery.dk/shop. I’ve published one product for testing purposes.

    #4480

    Ashanna
    Plugin's author

    Weird, it works with me… Do you use a child theme?

    Could you try this to see if any change is applied:

    add_filter( 'easy_booking_product_first_available_date', 'set_date_to_next_day', 10, 2 );
    
    function set_date_to_next_day( $first_available_date, $product ) {
        return 10;
    }

    #4481

    hellopeterjensen
    Participant

    No, not a child theme. And that code actually worked, which it also seems to do in general now. Weird. I’ll keep an eye on it.

    Thank you so much for your help!

    #4486

    hellopeterjensen
    Participant

    Hi again. Sorry Natasha, but not it doesn’t seem to work again 🙁

    The shop is live: https://mirabelle-bakery.dk/shop/

    Can I try putting the line of code in one of the plugin php files? Or what do you expect could work?

    #4494

    Ashanna
    Plugin's author

    Hello,

    Could you please contact me by email and give me a temporary admin access to your website?

    The code I gave you should work, I’d like to check a few things and it will be easier this way 🙂

    Thanks.
    Natasha

Viewing 15 posts - 1 through 15 (of 16 total)

The topic ‘[Resolved] Possibility to set 'First available date' in relation to current time’ is closed to new replies.

Want to know what's next with Easy Booking? Check the roadmap!