Conditional Logic Based on Day of the WeekPRO

In this tutorial we will build a WordPress form that shows a message if a date chosen is on a Saturday or Sunday. This same methodology can be used to create any conditional logic that is based on the day of a week.



Adding Fields

First we add three fields to the form. They are as follows:

  1. Date / Time field
  2. Number field (This could also be a hidden field)
  3. Message field

The Date / Time field is used to select a date. The Number field will contain the day of the week. The Message field will contain the message shown if the day of the week is Saturday or Sunday.

Setting the Number Field Default Value

The following is added to the Default Value setting of the Number field.

#text(#field_date_format(123, "N"))

WS Form - Conditional Logic Day of the Week - Number Field - Hidden Value

This syntax is used to insert the day of a date field:

Breaking this down:

  • #text keeps the value updated dynamically. If the Date / Time field is changed, WS Form will update this value.
  • #field_date_format returns a formatted date for a particular field ID. In this tutorial the Date / Time field has an ID of 123 and “N” returns the day of the week from 1 (Monday) through 7 (Sunday).

Creating the Conditional Logic

The following is an example of the conditional logic that will show the Message field if the chosen Date / Time is a Saturday or Sunday.

WS Form - Conditional Logic Day of the Week - Conditional Logic