### [How to Create Conditional Logic for Coupons](https://wpforms.com/developers/how-to-create-conditional-logic-for-coupons/)

**Published:** August 3, 2023
**Author:** Editorial Team

**Excerpt:** This tutorial will show you how easily you can create a form that will use conditional logic to apply the correct coupon to your form. 

**Content:**

## Introduction

Would you like to create conditional logic for coupons? With this tutorial, you’ll be able to build a dynamic form where the script intelligently selects the appropriate coupon based on the user’s selection. This comprehensive tutorial will guide you step-by-step through the process of creating this form and implementing the conditional script for automatic coupon application. Let’s dive right in!

## Creating the coupons

To begin, we’re going to create three new coupon codes. Each one is created to give a particular percentage amount for the coupon.

If you need help in creating coupons with WPForms, [please check out this guide for further assistance](https://wpforms.com/docs/coupons-addon/ "WPForms Coupons Addon").

![begin by creating the coupons you need for the form](https://wpforms.com/wp-content/uploads/2023/08/wpforms-create-coupons.jpg)

## Creating the form

Next, we’ll create the form and add our fields required. If you need any assistance with creating your form, [please review this useful documentation](https://wpforms.com/docs/creating-first-form/ "Creating Your First Form").

![create your form and add your fields](https://wpforms.com/wp-content/uploads/2023/08/wpforms-create-form.jpg)

## Adding the Dropdown options

Now that we’ve added our required fields to the form, let’s add a **Dropdown** field. We will use this field to base our conditional logic on for the coupon. Based on the option selected, the correct coupon code will be displayed.

For the purpose of this tutorial, we’re going to have our dropdown options as the following:

- — Select One —
- Code 1
- Code 2
- Code 3

![add a dropdown field with options that will be used to select the correct coupon code](https://wpforms.com/wp-content/uploads/2023/08/wpforms-conditional-coupon-dropdown-field.jpg)

## Apply Smart Logic for the Coupon field

Next, we’re going to add our **Coupon** field to the form. Because you’ve already assigned the form to these coupons in the first step, you’ll see the coupon codes when you add the field to your form.

![add a coupon field to your form](https://wpforms.com/wp-content/uploads/2023/08/wpforms-conditional-coupon-add-field.jpg)

However, since we don’t want this field to show until they’ve selected the code, we’re going to apply some conditional logic to the field as well. To apply this logic to the field, select the **Coupon** field and click the **Smart Logic** tab.

Tell the field to **Show** *this field if* the **Dropdown** **is not** the **— Select One —** we set up when defining the options of the dropdown field in the previous step. This way, when the form loads, the **Coupon**field will not be displayed until they select an option.

![apply smart logic to the coupon field to hide until the user has selected an option from the dropdown field](https://wpforms.com/wp-content/uploads/2023/08/wpforms-conditional-coupon-smart-logic.jpg)

## Adding the snippet

Now it’s time to add the snippet to your site. If you’re not sure how and where to add snippets to your site, [please review this helpful guide for more details](https://wpforms.com/developers/how-to-add-custom-php-or-javascript-for-wpforms/ "How to Add Custom PHP or JavaScript for WPForms").

```

/**
 * Conditional logic for coupons
 *
 * @link https://wpforms.com/developers/how-to-display-the-age-from-a-date-picker-field/
*/
  
function wpf_dev_conditional_logic_for_coupons() {
    ?>

**Categories:** Tutorials

**Tags:** Coupons, Javascript, JS

---

