WordPress.org

Ready to get started?Download WordPress

Forums

How to close pizza order site (or page) outside business hours? (15 posts)

  1. lemonadejoex
    Member
    Posted 1 year ago #

    I am building a pizza delivery order site. But the orders can be taken only during business hours. I would like the site (or the page with the order form) to automatically close and then open at certain hours of certain days (the times are different for weekdays and weekends). Is there a way to do that?

  2. alby54
    Member
    Posted 1 year ago #

    Simple Timed Content plugin?

  3. bythegram
    Member
    Posted 1 year ago #

    how's your php? should be pretty straight forward using an if statement to check the date(and time) and redirect if it is outside of the desired time.

  4. lemonadejoex
    Member
    Posted 1 year ago #

    Thanks guys

    My php is practicly non-existent :) that is why I was looking for a plugin :)

    Thanks for the tips, I will try the simple timed content plugin. I hope it will work, there are three types of business hours (mon-thur, fri-sat, sun), I hope it can combine all of them

    If not, I will cry for help for php instructions :)

  5. lemonadejoex
    Member
    Posted 1 year ago #

    No luck with the plugin, as it does not allow shortcodes in the timed content and I need those for the order form :(

  6. keesiemeijer
    moderator
    Posted 1 year ago #

  7. birgire
    Member
    Posted 1 year ago #

    hi, this gave me an idea of a shortcode that can display content during given opening hours in the week and can handle shortcodes inside it:

    [openinghours
     sun="11:00-22:30"
     mon="09:00-23:00"
     tue="09:00-23:00"
     wed="09:00-23:00"
     thu="10:15-23:00"
     fri="09:00-23:00"
     sat="09:00-24:00"
     debug="0"
     sorry="Sorry, we are closed now. Try again during the opening hours."]
     please order now!
     [some-orderform-shortcode]
    [/openinghours]

    Add this into your functions.php file:

    function my_openinghours($atts,$content=""){
            extract( shortcode_atts( array(
                    'sun' => '',
                    'mon' => '',
                    'tue' => '',
                    'wed' => '',
                    'thu' => '',
                    'fri' => '',
                    'sat' => '',
                    'sorry' => '',
                    'debug' => '0',
            ), $atts ) );
    
    $currT=time();
    $currYMD=date("Y-m-d",$currT);
    $currYMDHIS=date("Y-m-d H:i:s",$currT);
    $currWD=date("w",$currT);
    
    switch ($currWD){
            case 0:
                    $s=$sun;
                    break;
            case 1:
                    $s=$mon;
                    break;
            case 2:
                    $s=$tue;
                    break;
            case 3:
                    $s=$wed;
                    break;
            case 4:
                    $s=$thu;
                    break;
            case 5:
                    $s=$fri;
                    break;
            case 6:
                    $s=$sat;
                    break;
            default:
                    $s="";
    }
    
    $out=$sorry;
    
    if(strlen(trim($s))>0){
            $a=explode("-",$s);
            if(count($a)==2){
                    $from = $currYMD." ".$a[0].":00";
                    $to = $currYMD." ".$a[1].":00";
                    $fromT = strtotime($from);
                    $toT = strtotime($to);
                    if($currT>$from && $currT<$to){
                            $out=do_shortcode($content);
                    }
            }
    }
    
    if($debug=="1"){
            $out.="<br/>Debug: <br/>from:".$from."<br/> current:".$currYMDHIS."<br/> to:".$to."</br>";
    }
            return $out;
    }
    
    add_shortcode("openinghours","my_openinghours");

    Hope this helps

  8. lemonadejoex
    Member
    Posted 1 year ago #

    Wow, Birgire, that would be the perfecr solution!
    Unfortunately, when i set it up on the site, it always displays the sorry message no matter how i set up the opening hours.

    The second code is in the theme function.php file, the firts is around my order form shortcode.

    What did i do wrong? Does the wordpress time format have to be set in a certain way (my setting for date is: j. F Y, for time G:i)? Or could it be because I am runinng the WP site with Slovak, not English language files?

  9. birgire
    Member
    Posted 1 year ago #

    you could try debug="1" in the shortcode, then you can see the current time it is using.

  10. birgire
    Member
    Posted 1 year ago #

    ahh, sorry small mistake:

    replace this

    if($currT>$from && $currT<$to){

    with

    if($currT>$fromT && $currT<$toT){
  11. lemonadejoex
    Member
    Posted 1 year ago #

    Sorry, still does't work, the page is always closed.
    debug displays the current date in this format:
    current:2012-10-18 13:05:35

    i tried to disable the WP language files (the short forms of days mon, tue, etc. are translated), but no change either

  12. birgire
    Member
    Posted 1 year ago #

    hmm... strange - I have tested it with shortcode inside and it works.

    Here is the debug info I have

    Debug:
    from:2012-10-18 10:15:00
    current:2012-10-18 14:47:13
    to:2012-10-18 23:00:00

    and the current time is correctly between the from and to times.

    Can you paste all the debug info?

    I'm using this shortcode to test it

    [openinghours thu="10:15-23:00" debug="1" sorry="Sorry, we are closed now."] please order now![/openinghours]
  13. keesiemeijer
    moderator
    Posted 1 year ago #

    Tested it and it works with:

    [openinghours sun="11:00-22:30" mon="09:00-23:00" tue="09:00-15:00" wed="09:00-23:00" thu="10:15-14:59" fri="09:00-23:00" sat="09:00-24:00" debug="0" sorry="Sorry, we are closed now. Try again during the opening hours."]
     please order now!
     [some-orderform-shortcode]
    [/openinghours]

    And not with:

    [openinghours
     sun="11:00-22:30"
     mon="09:00-23:00"
     tue="09:00-23:00"
     wed="09:00-23:00"
     thu="10:15-23:00"
     fri="09:00-23:00"
     sat="09:00-24:00"
     debug="0"
     sorry="Sorry, we are closed now. Try again during the opening hours."]
     please order now!
     [some-orderform-shortcode]
    [/openinghours]

    I think WordPress adds <br/> to the shortcode content and breaks it.

  14. lemonadejoex
    Member
    Posted 1 year ago #

    Guys, it works, that is fantastic!
    The problem was only with the formatting as keesiemeijer pointed out.
    Thanks a lot birgire, this was a great help. I will send you a pizza if you will be around my town :)

  15. birgire
    Member
    Posted 1 year ago #

    ok cool, I'm a pizza-fan ;-)

    thanks @keesiemeijer for pointing out the formatting issue.

    Maybe I will develope this further into a plugin so other pizza-fans can use it too.

    Here is an upgraded versions that can handle holidays:

    http://xlino.com/projects/pizza-ordertime-content-with-weekly-opening-hours/

    ... all this pizza talk makes me hungry ;-)

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags