WPCode Logo

WPCode Documentation

Documentation, Reference Materials, and Tutorials for WPCode

Most Popular

Get free tips and resources right in your inbox, along with 500+ others

Follow Us

How to create advanced scheduling rules

Would you like a snippet to run only during business hours, on certain days of the week, or between two dates? All you need is a WPCode snippet and a paid WPCode license.

In this guide, we’ll walk you through scheduling WPCode snippets with start and end dates and with scheduling rules.

Requirements: The Schedule snippet dates and the scheduling rules need a paid WPCode license.

Before you get started, make sure WPCode is installed and activated on your WordPress site.

Setting a Start and End Date

To get started, we’ll open a snippet and give it a start and end date.

WPCode gives you two ways to schedule a snippet. For a single window with a fixed start and end, the Schedule snippet dates are the quickest option. For repeating schedules, such as weekdays only or business hours, you’ll use scheduling rules, which we cover in the next sections.

From your WordPress admin sidebar, go to Code Snippets » Code Snippets. Then click the title of the snippet you want to schedule.

The Code Snippets list in WPCode with an arrow pointing at a snippet title

In the snippet editor, scroll down to the bottom of the Insertion box. There, click the Start Date field in the Schedule snippet row and pick the date and time you want the snippet to start. Then set the End Date field the same way.

The Schedule snippet row in the Insertion box with a start date and an end date filled in and an arrow pointing at the Start Date field

Both fields are optional. With only a start date, the snippet runs from that moment on. With only an end date, it runs until that moment and then stops.

The end time is included, so an end of 23:59 keeps the snippet running through the last minute of that day.

After you save an active snippet with these dates, the Code Snippets list shows a Scheduled icon next to its status toggle. That makes scheduled snippets easy to spot later.

Choosing a Scheduling Rule

Scheduling rules are part of Smart Conditional Logic. They let you build schedules that repeat, such as every weekday, or combine a schedule with other rules. If you haven’t used conditional logic before, our guide on using Smart Conditional Logic explains how rules and groups work.

In the snippet editor, scroll down to the Smart Conditional Logic box and turn on the Enable Logic toggle. Then click + Add new group.

The Smart Conditional Logic box with Enable Logic switched on and an arrow pointing at the + Add new group button

The new group starts with a Logged-in rule. Next, click the Logged-in field to open the rule picker. Then click Advanced in the picker’s sidebar, where the four scheduling rules are listed:

  • Date: compares today’s date with a date you pick. It checks the whole day, so no time is involved.
  • Date & Time: compares the current date and time with a moment you pick, down to the minute.
  • Day of the Week: matches one or more days that you select.
  • Current time: compares the time of day with a time you pick, on any date.

The rule picker open on the Advanced category showing Date, Date and Time, Day of the Week, Current time, and WPCode Snippet, with an arrow pointing at Day of the Week

The fifth item in the list, WPCode Snippet, isn’t a scheduling rule. It checks whether another WPCode snippet is loaded on the page.

All four rules use your site’s timezone, which you set under Settings » General in WordPress. It’s worth checking this setting before you build a schedule, so 9:00 means 9:00 where your business is.

Running a Snippet on Certain Days

For our example, we’ll set up a live chat announcement that shows on weekdays from 9:00 AM to 5:00 PM. The first rule picks the days.

In the picker, choose Day of the Week. Leave the comparison on Is. Next, click the value field and select Monday through Friday.

A rule reading Day of the Week, Is, Monday, Tuesday, Wednesday, Thursday, Friday, with an arrow pointing at the selected days

The rule matches when today is any of the days you selected. To run a snippet on every day except a few, choose Is not and select the days to skip.

Limiting a Snippet to Business Hours

Next, we’ll add two Current time rules: one for the opening time and one for the closing time. Rules in the same group must all be true, so the snippet runs only on the right days and at the right hours.

Inside the group, click AND to add a second rule.

The Day of the Week rule with an arrow pointing at the AND button below it

Next, open the new rule’s picker and choose Current time from the Advanced category. Then set the comparison to Is on or After and the time to 09:00.

A second rule reading Current time, Is on or After, 09:00, with an arrow pointing at the comparison dropdown

Now click AND again and add another Current time rule. This time, set the comparison to Is Before.

When you click the value field, a time picker opens with hour, minute, and AM or PM controls. You can also type the time in 24-hour format.

A third rule reading Current time, Is Before, 17:00, with the time picker open showing 05:00 PM and an arrow pointing at the value field

For this rule, pick 5:00 PM, which the field shows as 17:00. Here’s the finished group.

A finished rule group reading Day of the Week Is Monday to Friday, Current time Is on or After 09:00, and Current time Is Before 17:00

Is Before 17:00 stops the snippet at 5:00 PM exactly. Is on or Before 17:00 keeps it running through 5:00 PM and stops it at 5:01 PM.

Current time compares with Is, Is Before, Is After, Is on or Before, and Is on or After. Pairing two of them sets the edges of your time range.

Running a Snippet Between Two Dates

For a one-time event, such as a holiday sale, use two Date & Time rules to mark when it starts and ends. Unlike the Schedule snippet dates, these rules can sit in the same group as other rules. For example, you can add them to the weekday and business hours group above.

In a group, choose Date & Time from the Advanced category. Next, set the comparison to Is on or After and pick the start date and time.

Then click AND and add a second Date & Time rule. For this rule, set the comparison to Is Before. When you click its value field, a calendar opens so you can pick the end date and time.

Two Date and Time rules, the first set to Is on or After November 27 at 00:00, with the calendar open on December for the second rule and an arrow pointing at its value field

Here, the snippet starts at midnight on November 27 and stops at midnight on December 1, so it runs through the whole of November 30.

A finished rule group reading Date and Time Is on or After November 27 at 00:00 and Date and Time Is Before December 1 at 00:00

If you don’t need a specific time, the Date rule works the same way with whole days. For example, Date Is on or Before November 30 includes all of November 30.

Saving Your Schedule

When your schedule is ready, click Update at the top of the snippet editor. On a snippet you haven’t saved yet, this button reads Save Snippet instead.

An arrow pointing at the Update button at the top of the WPCode snippet editor, next to the Inactive status toggle

Your schedule takes effect once the snippet is saved and its status toggle, just left of the Update button, reads Active.

That’s it! You now know how to schedule WPCode snippets with start and end dates and with scheduling rules. Next, take a look at our complete guide to snippet locations to choose where on the page your scheduled snippet appears.

Frequently Asked Questions

Below, we’ve answered some of the most common questions about scheduling snippets in WPCode.

Which timezone does WPCode use for my schedule?

Both the Schedule snippet dates and the scheduling rules use the timezone set in your WordPress settings under Settings » General. A visitor’s own timezone doesn’t change when the snippet runs.

Can I run a snippet overnight, such as from 10:00 PM to 6:00 AM?

Yes, with two groups. WPCode compares Current time within a single day, so one group with Is on or After 22:00 and Is Before 06:00 never matches. Instead, create one group with Current time Is on or After 22:00, and a second group with Current time Is Before 06:00. The snippet runs when either group matches.

How do I pause a recurring schedule for a holiday?

To skip a single day, add a Date rule with Is not and that date to the group. To skip several days in a row, duplicate the schedule into two groups. Add Date Is Before your first closed day to one group, and Date Is After your last closed day to the other.

What happens if I set Schedule snippet dates and scheduling rules on the same snippet?

Both apply. The snippet runs only inside the Schedule snippet window and only when its conditional logic rules match.

Do schedules apply when I use a snippet as a shortcode?

Yes. WPCode checks the Schedule snippet dates and the conditional logic rules when the snippet’s shortcode runs, as well as when it inserts the snippet automatically.

A shortcode outputs the snippet only where its rules match, even when the Show dropdown is set to Hide. Our guide on using Smart Conditional Logic covers this in more detail.

When does WPCode check my snippet’s schedule?

WPCode checks the schedule each time WordPress builds a page. If your site uses a page caching plugin, visitors may see a cached copy of the page that was built earlier. In that case, the snippet appears or disappears once the cache refreshes. See how to clear your cache in WordPress to refresh it right away.

Still stuck? How can we help?

Last Updated on

Get Started Today & Add Your Own Snippets

Future-proof your website with WPCode Snippets and improve the way you manage code across all your websites.