Table of Contents

How To Create Discount Codes

Danielle Kellogg Updated by Danielle Kellogg

This guide uses Validation Rules and Conditional Rules to apply a percentage discount to a total when a user enters a valid code. You can work through these instructions step-by-step by adding discount code functionality to the Bakery Manager app template (add this template to your account by clicking on the link).

Scenario

The bakery sends out discount codes in their monthly newsletters. Subscribed members can take advantage of an order discount by entering the discount code prior to checkout.

Requirements

  1. Object: The Schema section of your Builder has an object that stores records that contain the information your users will use to check out. In our example, this object is named Orders.
  2. Numeric field: The Orders object has a numeric field to apply the discount rate to. In our example, this is a Sum field called Order Items Total. This could be a number field, an equation field or a formula field
  3. Edit form: A page set up for your Live App has an Edit Form for your Order where the user can enter a discount code.

Steps

Add discount fields to the Orders object

Add the following fields to the Orders object.

  1. Add a Short Text Field called Discount Code.
    • This will be where the user will input the discount code before checkout.
  2. Add a Number Field called Discount Amount.
    • This field will be used to apply the discount rate to the order total. Conditional rules will be added to this field in the next step.
    • Be sure to set this field up with Decimals setup, Decimal places of 2 and a Currency format.
  3. Add an Equation Field (Numeric Equation Type) called Order Total.
    • This field will be used to subtract the Discount Amount field from the Order Items Total field. You will enter {Order Items Total}-{Discount Amount} in the Equation input box.
    • Be sure to set up your formatting on this equation field with Decimals setup, Decimal places of 2 and a Currency format.
  4. Update the Equation in the Amount Due field to be {Order Total}-{Total Charged}.
The sequential order the fields are listed in is important. The Discount Amount field needs to be listed above the Order Total field so that it can be calculated prior to Order Total.

Add validation rules to check for valid codes

The Discount Code field needs to have Validation Rules added in order to check for a valid code. If the entered code does not match your validation rule, they will see your custom error message.

One code per order
  1. Click to edit the Discount Code field, click on the "Validation Rules" tab, then click the checkbox next to “Add field validation rules”.
  2. Add this rule:
    • When “Discount Code” “is not” “LARGE-ORDER”
    • Show message “This is not a valid code, please use a different one.”
Multiple codes per order
  1. Click to edit the Discount Code field, click on the "Validation Rules" tab, then click the checkbox next to “Add field validation rules”.
  2. Add these validation rules:
  3. When “Discount Code” “is not” “HALF-OFF”
  4. When “Discount Code” “is not” “LARGE-ORDER”
  5. Show message “This is not a valid code, please use a different one.”

Add conditional rules to set the discount amount

The Discount Amount needs Conditional Rules to apply a discount rate depending on which code was entered. Each discount code can have multiple conditions - for example if your discount also requires a total higher than $100.

You can check for different discount codes by adding multiple conditional rules. Regardless of the number rules, you must have one default rule that leaves this field blank if no valid code is entered.

  1. Click to edit the Discount Amount field, click on the "Conditional Rules" tab, then click the checkbox next to “Add conditional rules”.
  2. Add these rules:
    • Rule #1
      • When “Discount Code” “is” “HALF-OFF”
      • Set “Discount Amount” “to a custom value” “.50”
    • Rule #2
      • When “Discount Code” “is” “LARGE-ORDER”
      • When “Order Items Total” “is higher than” “99”
      • Set “Discount Amount” “to a custom value” “.10”
    • Rule #3
      • Every record
      • Set “Discount Amount” “to a custom value” “0”

Calculate the total using an equation

Now that the percent discounted is set, it needs to be used in conjunction with a Total to calculate the order total.

  1. Edit the Order Total equation field and enter the following formula so it calculates the total of the order minus the discount: {Line Items Total} - {Discount Amount}

Add discount fields to your form

In order for this to work, the Order record must exist already, so we need to use an Edit Form.

The Form can include any other Order field, but it needs the Discount Code field at the minimum. This setup works well on an Order Details page where you can add that Edit Order form easily.

  1. Under the Pages section in the Builder, and then under the "Customer > Orders Login" login page, you’ll see the Order Details page. Click on that page in the left bar page tree. Add a new menu that links to a form here to “Update this page’s Order”.
  2. Click to edit the Menu view and click the edit pencil on the newly created “Edit Order” menu button.
    • Rename to “Add Discount Code” and save the changes.
  3. Under the menu view, click on the “Edit Order” page.
    • On the page settings update the page name to “Add Discount Code” and the Page URL to “add-discount-code”.
    • Check the checkbox next to “Display page in a modal popup” and click “Update Settings”.
  4. Back in the page preview, click to edit the “Edit Order” form.
    • Remove the view title of “Edit Order” and click “Save”.
    • Click the gear icon in the top right and rename the view title and view name to “Add Discount Code”.
    • Remove all inputs on the form except for the Discount Code field.
    • Under the Options section, rename the “Submit Button Text” to “Apply Discount Code”.
    • Finally, under the Form Rules section, update the Action to “Redirect to an existing page” and choose “My Orders > Order Details”. This will ensure the page will refresh and correctly apply the Discount Code.
  5. Be sure to click Save Changes on this form.

Update the checkout to use the new Order Total field

In order to make sure the checkout uses this new Order Total field that will include the discount amount, the “Checkout” Payment form needs to have the Payment total field updated from the Order Items Total field to the Order Total field.

  1. Click on the "Checkout" page in the left bar page tree. Then, click to edit the “Checkout” Payment form view.
  2. Under the Settings section, change the field selected in the drop-down for "Payment total field" from “Order Items Total” to “Order Total”. Be sure to click Save Changes on the form.
  3. You’ll likely want to make this same switch on the Payment Summary section fields that are displayed there.

Test it out

Head on over to the Live App view of these pages and test it out!

How did we do?

Accept Payments in a Live App

Contact