Get Google Business Opening hours with PHP

Use your Google Business account to show your opening hours on your own site. Change your opening hours in Google Business and it will change on your site.

Google My Business is a free and easy-to-use tool for businesses and organizations to manage their online presence across Google, including Search and Maps.

To keep your business information on Google accurate and up to date, you can edit your Business Profile on Google. To help potential customers find and learn more about your business, you can change information like your address, hours, contact info, and photos.

This information of your Business in Google Business can be used by using an API. If you want to show your opening hours on your own site you will have to use such an API.

But if you know a little PHP and use my Script you can use your Google Business opening hours for your own site!

If you need to change the Opening Hours, just change them in Google Business and your site will automaticly show the new Opening Hours!

You can even show the Opening Hours in your Locales / Country own langauge.

PHP Script for showing Google Business Hours.

    function get_business_hours($place_id, $key, $lang = Null) {    
        if (!isset($lang)){
            $lang = get_locale();
        $url = "{$place_id}&key={$key}&language={$lang}";

        $json = file_get_contents($url);
        # Converts it into a PHP object
        $data = json_decode($json, true);

        $weekday_hours = $data["result"]["opening_hours"]["weekday_text"];

    #    $html_wh = '<ul class="list-group">';
    #    foreach($weekday_hours as $i => $item) {
    #        $html_wh .= "<li class='list-group-item'>{$item}</li>";
    #    }
    #    $html_wh .= '</ul>';

        $html_wh = "";
        foreach($weekday_hours as $i => $item) {
            $day = explode(": ", $item);
            $html_wh .= "<div class=\"row\">";
            $html_wh .= "<div class=\"column\">{$day[0]}</div>";
            $html_wh .= "<div class=\"column\">{$day[1]}</div>";
            $html_wh .= "</div>";

        return $html_wh;

    # To get your API-Key go to:
    $key = "";

    # To get your Place ID go to:
    $place_id = "ChIJg_Eva1qJxEcRa3s2EXuTL7s";

    # You can find a language list on my site.
    $lang = "nl";

    echo get_business_hours($place_id, $key, $lang);

Language List for the PHP Google Business Hours

'af'= 'Afrikaans'
'sq'= 'Albanian'
'ar'= 'Arabic'
'az'= 'Azerbaijani'
'eu'= 'Basque'
'bn'= 'Bengali'
'be'= 'Belarusian'
'bg'= 'Bulgarian'
'ca'= 'Catalan'
'zh-CN'= 'Chinese Simplified'
'zh-TW'= 'Chinese Traditional'
'hr'= 'Croatian'
'cs'= 'Czech'
'da'= 'Danish'
'nl'= 'Dutch'
'en'= 'English'
'eo'= 'Esperanto'
'et'= 'Estonian'
'tl'= 'Filipino'
'fi'= 'Finnish'
'fr'= 'French'
'gl'= 'Galician'
'ka'= 'Georgian'
'de'= 'German'
'el'= 'Greek'
'gu'= 'Gujarati'
'ht'= 'Haitian Creole'
'iw'= 'Hebrew'
'hi'= 'Hindi'
'hu'= 'Hungarian'
'is'= 'Icelandic'
'id'= 'Indonesian'
'ga'= 'Irish'
'it'= 'Italian'
'ja'= 'Japanese'
'kn'= 'Kannada'
'ko'= 'Korean'
'la'= 'Latin'
'lv'= 'Latvian'
'lt'= 'Lithuanian'
'mk'= 'Macedonian'
'ms'= 'Malay'
'mt'= 'Maltese'
'no'= 'Norwegian'
'fa'= 'Persian'
'pl'= 'Polish'
'pt'= 'Portuguese'
'ro'= 'Romanian'
'ru'= 'Russian'
'sr'= 'Serbian'
'sk'= 'Slovak '
'sl'= 'Slovenian'
'es'= 'Spanish'
'sw'= 'Swahili'
'sv'= 'Swedish'
'ta'= 'Tamil'
'te'= 'Telugu '
'th'= 'Thai'
'tr'= 'Turkish'
'uk'= 'Ukrainian'
'ur'= 'Urdu'
'vi'= 'Vietnamese'
'cy'= 'Welsh'
'yi'= 'Yiddish'

Changing your Google Business opening hours

To change your opening hours, sign in to Business Profile on Google, choose 'Info' from the menu and select 'Hours'. Use the drop-down arrows to set the 'Opens at' and 'Closes at' times for each day. To put a break in your opening hours, if you close for lunch, for example, you can create two entries for the same day.

Have Fun!

Did you find this article valuable?

Support Theo van der Sluijs by becoming a sponsor. Any amount is appreciated!