Giter VIP home page Giter VIP logo

php-store-hours's Introduction

PHP Store Hours

PHP Store Hours is a simple PHP class that outputs content based on time-of-day and-day-of-week. Simply include the script in any PHP page, adjust opening and closing hours for each day of the week and the script will output content based on the time ranges you specify.

###Easily set open hours for each day of the week

// REQUIRED
// Define daily open hours
// Must be in 24-hour format, separated by dash 
// If closed for the day, leave blank (ex. sunday)
// If open multiple times in one day, enter time ranges separated by a comma
$hours = array(
  'mon' => array('11:00-20:30'),
  'tue' => array('11:00-13:00', '18:00-20:30'),
  'wed' => array('11:00-20:30'), 
  'thu' => array('11:00-1:30'), // Open late
  'fri' => array('11:00-20:30'),
  'sat' => array('11:00-20:00'),
  'sun' => array('') // Closed all day
);

###Add exceptions for specific dates / holidays

// OPTIONAL
// Add exceptions (great for holidays etc.)
// MUST be in format month/day
// Do not include the year if the exception repeats annually
$exceptions = array(
  '2/24' => array('11:00-18:00'),
  '10/18' => array('11:00-16:00', '18:00-20:30')
);

###Customize the final output with shortcodes Choose what you'd like to output if you're currently open, currently closed, or closed all day. Shortcodes add dynamic times to your open or closed message.

// OPTIONAL
// Place HTML for output below. This is what will show in the browser.
// Use {%hours%} shortcode to add dynamic times to your open or closed message.
$template = array(
  'open' => "<h3>Yes, we're open! Today's hours are {%hours%}.</h3>",
  'closed' => "<h3>Sorry, we're closed. Today's hours are {%hours%}.</h3>",
  'closed_all_day' => "<h3>Sorry, we're closed today.</h3>",
  'separator' => " - ",
  'join' => " and ",
  'format' => "g:ia", // options listed here: http://php.net/manual/en/function.date.php
  'hours' => "{%open%}{%separator%}{%closed%}"
);

###Available Methods ####render(); This is the default method that outputs the templated content. You'll most likely want to use this.

$store_hours = new StoreHours($hours, $exceptions, $template);
$store_hours->render();

####hours_today(); This returns an array of the current day's hours.

$store_hours = new StoreHours($hours, $exceptions, $template);
$store_hours->hours_today();

####is_open(); This returns true/false depending on if the store is currently open.

$store_hours = new StoreHours($hours, $exceptions, $template);
$store_hours->is_open();

###Use Cases ####Multiple stores / sets of hours If you'd like to show multiple sets of hours on the same page, simply invoke two separate instances of StoreHours(). Remember to set the timezone before each new instance.

// New York Hours
date_default_timezone_set('America/New_York'); 
$nyc_store_hours = new StoreHours($nyc_hours, $nyc_exceptions, $nyc_template);
$nyc_store_hours->render();

// Los Angeles Hours
date_default_timezone_set('America/Los_Angeles'); 
$la_store_hours = new StoreHours($la_hours, $la_exceptions, $la_template);
$la_store_hours->render();

###Troubleshooting If you're getting errors or if times are not rendering as expected, please double check these items before filing an issue on GitHub:

  • Make sure your timezone is configured
  • Ensure all exceptions use the month/day format
  • Verify that StoreHours.class.php is properly included on the page

Please report any bugs or issues here on GitHub. I'd love to hear your ideas for improving this script or see how you've used it in your latest project.

##Sites using PHP Store Hours

php-store-hours's People

Contributors

coryetzkorn avatar crookedneighbor avatar tibbi avatar

Watchers

James Cloos avatar Ryan avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.