### [How to Show a Payment Field Based on a Date in WordPress](https://wpforms.com/how-to-show-a-payment-field-based-on-a-date-in-wordpress/)

**Published:** January 7, 2025
**Author:** David Ozokoye

**Excerpt:** Creating conditional payment fields in WordPress forms is straightforward with WPForms, especially for handling event registrations and time-sensitive services. If you want to show a payment field when a user selects a certain date in your form, utilizing the Calculations addon offers an effective solution.

By integrating WPForms with the Calculations addon, you can dynamically display payment fields based on user input dates, ensuring seamless user interactions without complex coding. This guide walks you through setting up conditional payment fields, from installing WPForms and the necessary addon to utilizing Hidden fields and custom formulas for date comparisons.

Continue reading to see two practical implementations of using a Date field’s value as a parameter for conditional logic in WPForms.

**Content:**

Displaying payment fields based on specific dates is a common requirement for many WordPress websites. This is particularly useful to those handling event registrations, seasonal bookings, or time-sensitive services.

Using the WPForms Calculations addon, you can display a payment field in your form only if your customer selects certain dates in the Date / Time field.

In this guide, I’ll walk you through how to show a payment field based on date input on your WordPress site.

## How to Show a Payment Field Based on a Date in WordPress

- [Step 1: Install and Activate WPForms Plugin](#install-wpforms-plugin)
- [Step 2: Install the Calculations Addon](#install-calculations-addon)
- [Step 3: Creating Your Payment Form](#creating-your-form)
- [Step 4: Enable Logic to Show Payment Fields Based on Date Input](#enable-logic-to-show-payment-field)
- [Step 5: Publish Your Payment Form](#publish-payment-form)

### Step 1: Install and Activate WPForms Plugin

WPForms is the best drag and drop form builder plugin for creating basic and advanced forms in WordPress.

From [simple contact forms](https://wpforms.com/how-to-create-a-simple-contact-form-in-wordpress/) to more [advanced features](https://wpforms.com/features/) like [conditional logic](https://wpforms.com/features/conditional-logic/), it’s a reliable tool that has worked well for me on multiple sites.

The [Pro license of WPForms](https://wpforms.com/pricing/) includes access to the [Calculations addon](https://wpforms.com/docs/calculations-addon/ "Calculations Addon"), which lets you perform simple and complex mathematical operations on your WordPress forms.

[![The WPForms pricing page. ](https://wpforms.com/wp-content/uploads/2024/08/WPForms-Pricing-Page.png)](https://wpforms.com/pricing/)Once you’ve purchased the Pro license, you should install and activate WPForms on your WordPress site. If this is your first time, check out this guide to learn [how to install WPForms](https://wpforms.com/docs/install-wpforms-plugin/ "Installing the WPForms Plugin").

[Build Your WordPress Form Now](https://wpforms.com/pricing/)

### Step 2: Install the Calculations Addon

After installing the WPForms plugin, you’ll also need to install the [Calculations addon](https://wpforms.com/features/calculations-addon/).

To install the addon, head into the WordPress admin area and go to **WPForms » Addons.** Then scroll down till you find the **Calculations** addon, or use the search bar. When you find it, click **Install Addon**.

![Install the calculations addon to show payment field based on date](https://wpforms.com/wp-content/uploads/2024/12/install-calculations-addon.png "Install Calculations Addon")Once you’ve installed and activated the Calculations addon on your site, proceed to create your WordPress form.

### Step 3: Creating Your Payment Form

You [can build your form from scratch](https://wpforms.com/how-to-create-a-user-registration-form-in-wordpress/#Step_2_Activate_the_User_Registration_Addon), use a form template, or [generate forms with WPForms AI](https://wpforms.com/how-to-use-ai-to-create-forms-in-wordpress/ "How to Use AI to Create Forms in WordPress"). For this tutorial, I’ll create a new form from scratch.

To start, navigate to **WPForms » Add New**. Then, hover over the **Blank Form** widget and click **Create Blank Form**.

![Create blank form](https://wpforms.com/wp-content/uploads/2024/12/create-blank-form.png "Click the Create Blank Form Button")In the form builder, go ahead and add the fields you need to your form. You can drag and drop a field or click on it to add it to the form builder.

## Pro Tip

When creating a payment form, you’ll need to include one of the payment field types, like the Single Item field. Also, you’ll need to add a credit card field to your form and set the payment type and transaction amount. For more details, please see our tutorial on [accepting card payments in WordPress forms](https://wpforms.com/how-to-accept-payments-with-stripe/).

For this tutorial, I’ll assume you’ve already added your payment fields and configured your payment and field settings. We’ll focus on implementing the logic to hide/show the payment field based on a date input.

**Also Read**: [How to View Your Form History in WordPress](https://wpforms.com/how-to-view-your-form-history-in-wordpress/)

### Step 4: Enable Logic to Show a Payment Field Based on Date Input

In this section, I’ll show you two practical examples of how you can hide/show a payment field on your form based on input from the Date / Time field.

#### Showing a Payment Field Based on Date Input

To do so, I’ll start by adding a Date / Time field and 2 Hidden fields to my form. I’ll use the Multiple Items field as my payment field. So, make sure to include it in your form as well.

![Add form fields](https://wpforms.com/wp-content/uploads/2024/12/add-form-field.png)Now click the **Date / Time** field to access its Field Options panel. Then select the **Advanced** tab.

![Select advanced tab](https://wpforms.com/wp-content/uploads/2024/12/select-advanced-tab.png "Select the Advanced Tab")Once here, confirm the date format. By default, this is set to **m/d/Y**, where **m** stands for the month, **d** represents the day, and **Y** represents the year.

![Confirm Date field format](https://wpforms.com/wp-content/uploads/2024/12/date-format.png "Check Date Field Format")After confirming the date format, click on one of the Hidden fields you added to your form and change the field’s label. I’ve named mine **Default Date**, but you can choose any name you want.

![Enter field label for Hidden field](https://wpforms.com/wp-content/uploads/2024/12/edit-field-label.png "Enter Field Label for Hidden Field")Next, click the **Advanced** tab and set the **Default Value** of the field to the date you want to check in the conditional logic.

![Setting default value for hidden field to show payment field based on date](https://wpforms.com/wp-content/uploads/2024/12/default-value.png "Setting a Default Value for Hidden Field")## Pro Tip

Make sure to write the date in the same format as the Date / Time field on your form.

After that, click on the second Hidden field on your form and select the **Advanced** tab. Then, toggle the **Enable Calculation** option to the on position.

![Enable calculation option](https://wpforms.com/wp-content/uploads/2024/12/enable-calculation.png "Enable Calculation on Hidden field")In the calculation formula builder, I’ll write a logic to compare the value the user selects on the Date / Time field with the default date I specified in the first Hidden field. If they match, we’ll set the field’s value to **1**. Otherwise, the calculation will return 0. Here’s the formula to implement this logic:

```

if (  $F12_date ==  $F14  ):
	1
else:
	0
endif; 
```

In the formula above, the variable `$F12_date` references the date subfield in the Date / Time field. While `$F14` represents the Hidden field where I specified a default date.

![Formula to show payment field based on date input](https://wpforms.com/wp-content/uploads/2024/12/formula-builder-if-statement.png)You’ll need to replace the numbers in the variable names so they match with the fields on your form. Please see our tutorial to learn more about [building formulas with the Calculations addon](https://wpforms.com/docs/building-formulas-with-the-calculations-addon/#field-variables).

After adding the formula, click on the payment field you’d like to enable conditional logic. Then select the **Smart Logic** tab and toggle the **Enable Conditional Logic** option to the on position.

![Enable conditional logic](https://wpforms.com/wp-content/uploads/2024/12/enable-conditional-logic.png "Enabling Conditional Logic")Once enabled, you’ll need to set the condition so it checks the Hidden field with calculations enabled. I’ve set the logic to **Show this field if Hidden field is 1**. This means if the formula that compares the Date / Time field value against the default date I specified is true, the Payment field will show in the form.

![Conditional logic rule to show payment field based on date](https://wpforms.com/wp-content/uploads/2024/12/conditional-logic-rule.png "Configure Conditional Logic Rule")After enabling the conditional logic, make sure to save your changes by clicking the **Save** button.

![Save changes to show payment field based on date](https://wpforms.com/wp-content/uploads/2024/12/save-changes-1.png "Saving Your Form Changes")When you preview the form in your site’s frontend, the payment field will be hidden by default until you select a date from the Date / Time field.

![Form preview excluding payment field](https://wpforms.com/wp-content/uploads/2024/12/form-preview-1.png "Form Preview Excluding Payment Field")If the date you select matches the one specified in the Default Date Hidden field, the payment field will appear. Users can now proceed to select a payment option and complete their purchase.

![Form preview showing payment field based on date field input](https://wpforms.com/wp-content/uploads/2024/12/form-preview-with-payment-field.png "Form Previewing Displaying Payment Field")#### Showing Payment Field Based on User Age

In this example, we’ll only show the payment field if the user is above 18 years. To get started, I’ll add 2 Hidden fields, a Date / Time field, and the Single Item field.

Then select one of the Hidden fields and change the label to **Current Date**.

![Change hidden field label](https://wpforms.com/wp-content/uploads/2024/12/current-date.png "Changing Hidden field Label")Next, click the **Advanced** tab and toggle on the **Enable Calculation** option.

![Enable calculation option](https://wpforms.com/wp-content/uploads/2024/12/enable-calculation.png "Enable Calculation on Hidden field")In the formula builder, go ahead and add the function below.

```

now()
```

![Function to display current date and time](https://wpforms.com/wp-content/uploads/2024/12/now-function.png "Function to Display Current Date and Time")This function will set the value of the Hidden field to the current date and time.

Next, select the second Hidden field and set the Label to **Age Calculator**.

![Change label to age calculator](https://wpforms.com/wp-content/uploads/2024/12/age-calculator-label.png "Change Hidden Field Label")Then select the **Advanced** tab and toggle on the **Enable Calculation** option. In the formula builder, add the function below.

```

years( $F12, $F14 )
```

The `years()` function will check the date difference between two dates and return the difference in years.

![Age calculator formula](https://wpforms.com/wp-content/uploads/2024/12/age-calculator-formula-new.png "Age Calculator Formula")`$F12` and `$F14` are the variable names for the **Date / Time** and the **Current Date** fields, respectively. Make sure to replace the numbers to match the ones on your fields.

After adding the formula to the Age Calculator, select the payment field on your form to open its Field Options panel. Then, navigate to the **Smart Logic** tab and toggle on the **Enable Conditional Logic** option.

![Enable conditional logic to show payment field based on a date](https://wpforms.com/wp-content/uploads/2024/12/enable-conditional-logic-single-item.png "Enabling Conditional Logic")Next, choose the **Age Calculator** field from the dropdown in the conditional logic rule.

![Choose age calculator field](https://wpforms.com/wp-content/uploads/2024/12/select-age-calculator.png "Choose Age Calculator Field")After that, choose the **greater than** operator from the dropdown.

![Choose the greater than operator](https://wpforms.com/wp-content/uploads/2024/12/greater-than.png "Choose the Greater Than Operator")Finally, enter **17** in the value. The rule should be **Show this field if Age Calculator is greater than 17**. This logic is useful for regulating online payments and ensuring appropriate payment status compliance.

![Conditional logic rule to show payment field based on a date](https://wpforms.com/wp-content/uploads/2024/12/conditional-logic-rule-age-calculator.png)After adding the logic, be sure to save your changes. When you preview the form, the payment field will be hidden by default until the user specifies their age.

![Form preview with payment field hidden](https://wpforms.com/wp-content/uploads/2024/12/form-preview-dob.png)The field will only show if the user’s age is 18 and above.

![Form preview now show payment field based on date input](https://wpforms.com/wp-content/uploads/2024/12/payment-field-visible.png "Payment Field Showing in Form Preview")### Step 5: Publish Your Payment Form

Finally, let’s add the payment form to a page. To do so, click the **Embed** button at the top right corner of the form builder.

![Embed form button](https://wpforms.com/wp-content/uploads/2024/12/click-embed.png "Embed Form")You’ll have the option of publishing your form on a new or existing page. For this guide, I’ll choose the **Create New Page** option.

![Decide how you want to embed your form](https://wpforms.com/wp-content/uploads/2024/12/create-new-form.png "Create New Page")Give your new page a name and click **Let’s Go**.

![Name your page and proceed](https://wpforms.com/wp-content/uploads/2024/12/lets-go.png "Name Your Page and Proceed")You’ll be directed to the WordPress page editor with your form embedded on the page. Click the **Publish** button to publish your page.

![Publish the page](https://wpforms.com/wp-content/uploads/2024/12/publish-page.png "Publishing Your Page")When you check this page on the frontend, the payment field on your form will be hidden until the Date field’s value matches the one specified in your conditional logic rule. Note that it’s also possible to [embed your forms using a shortcode or widget](https://wpforms.com/how-to-embed-a-form-on-your-website/), as well.

### FAQs — Conditionally Show a Payment Field Based on Date Input

These are answers to some of the top questions we see about showing a payment field based on date input.

#### What happens if the date field is left empty?

If the date field is empty, the calculation will return 0, effectively hiding the payment field. I recommend making the date field required to prevent this situation.

#### How do I show the date in WordPress?

If you’re using the Calculations addon in WPForms, you can show the date using the `now()` function. When you enter the function in the formula builder, the field’s value will be set as the current date and time.

### Next, Accept Recurring Payments in WordPress

And that’s it! You’ve now learned 2 practical ways to show a payment field based on date input in WordPress. The process I explained in this tutorial can also be applied to subscription-based payment forms.

You can check out our tutorial to learn [how to accept recurring payments in WordPress](https://wpforms.com/how-to-accept-recurring-payments-on-your-wordpress-forms/) for details on how to sell subscriptions with WPForms.

[Build Your WordPress Form Now](https://wpforms.com/pricing/)

Ready to build your form? Get started today with the easiest WordPress form builder plugin. [WPForms Pro](https://wpforms.com/pricing) includes lots of free templates and offers a 14-day money-back guarantee.

If this article helped you out, please follow us on [Facebook](https://facebook.com/wpforms) and [Twitter](https://twitter.com/easywpforms) for more free WordPress tutorials and guides.

**Categories:** WordPress Tutorials

**Tags:** calculations, calculations addon, date calculations, payment forms, wpforms pro

---

