How to Set Store Hours in Magento Admin. Area

After working on a few Magento e-commerce sites, we’ve come across a few tricks that are worth sharing. Today we’ll focus on setting your store hours in one central location and having this setting cascade to Magento’s transactional emails.

By default, Magento’s order confirmation emails read something like this:

Thank you for your order from {Store Name}. Once your package ships we will send an email with a link to track your order. You can check the status of your order by logging into your account. If you have any questions about your order please contact us at {Support Email} or call us at {Phone Number} Monday – Friday, 8am – 5pm PST.

Your order confirmation is below. Thank you again for your business.

For a rather generic block of copy there’s one detail that’s oddly hard-coded: “Monday – Friday, 8am – 5pm PST.” Sure, these are pretty typical support hours but the timezone used has nothing to do with the store’s timezone configuration. This automatically creates more work for any stores that aren’t in the Pacific timezone as every email template that contains that line will need to be updated.

The complete list of email templates that need updated are:

  • New Credit Memo
  • New Credit Memo for Guest
  • New Invoice
  • New Invoice for Guest
  • New Order
  • New Order for Guest
  • New Shipment
  • New Shipment for Guest

That’s a total of eight separate locations where you’ll need to replace the default store hours with your store’s support times. Rather than hard-code the store hours over and over eight times, we can create a simple Magento extension to add a “Store Hours” field to the store configuration in System › Configuration › General › Store Information:

A "Store Hours" field in the Magento "Store Information" configuration page

Our extension only requires three files: etc/config.xml (defines our module), etc/system.xml (adds the field to our “Store Information” configuration), and Bii_StoreHours.xml (tells Magento to use our module). You may also download the extension files from Github.

To get started, create a “Bii” directory in app/code/local/ and add a “StoreHours” subdirectory. Within app/code/local/Bii/StoreHours/ create an “etc” subdirectory, then add the following files:

app/code/local/Bii/StoreHours/etc/config.xml

<?xml version="1.0" encoding="UTF-8"?>
<!-- Adds a "Store hours" field to System > Configuration > General > Store Information -->
<config>
  <modules>
    <Bii_StoreHours>
      <version>0.1.0</version>
    </Bii_StoreHours>
  </modules>
</config>

app/code/local/Bii/StoreHours/etc/system.xml

<?xml version="1.0"?>
<config>
  <sections>
    <general>
      <groups>
        <store_information translate="label">
          <fields>
            <store_hours translate="label">
              <label>Store Hours</label>
              <frontend_type>text</frontend_type>
              <sort_order>20</sort_order>
              <show_in_default>1</show_in_default>
              <show_in_website>1</show_in_website>
              <show_in_store>1</show_in_store>
              <comment>Will be used in transactional emails</comment>
            </store_hours>
          </fields>
        </store_information>
      </groups>
    </general>
  </sections>
</config>

Finally, create a file in app/etc/modules named “Bii_StoreHours.xml” and paste the following into it:

<?xml version="1.0" encoding="UTF-8"?>
<config>
  <modules>
    <Bii_StoreHours>
      <active>true</active>
      <codePool>local</codePool>
    </Bii_StoreHours>
  </modules>
</config>

Once the files are in place, visit System › Configuration › General › Store Information and look for the “Store Hours” field (you may need to clear your Magento cache, log out, then log back in before the field will appear). Put in your store hours and click “Save Config.”

Now that you’ve set your store hours, we need to make use of this information. Create or edit the email templates we listed above by visiting System › Transactional Emails. Find any instances of “Monday – Friday, 8am – 5pm PST” and replace it with the {{config path='general/store_information/store_hours'}} variable. Magento will replace this with whatever value you have saved in our new “Store Hours” field.

Inserting the store hours as a variable in a Magento email template

If you created a new email template in order to use our {{config path='general/store_information/store_hours'}} variable, you’ll need to tell Magento to use this template instead of the system default. All eight of these templates are assigned on System › Configuration › Sales Emails.

Hopefully this saves you time when managing your Magento store. If you have any questions or are interested in hiring us for Magento work, please drop us a line!

Related Posts

Developers collaborate to launch a client-focused site successfully and efficiently.
Having an up-to-date website can be a clear contributor of success.
Life as a developer at Buckeye Innovation: Hear from our team members themselves.

Want to Connect?