If you sell products with WooCommerce and use Gravity Forms, then you most likely have a need to populate order data into a form. Not only does order data offer valuable insights into your customers’ buying habits, it’s often utilized in customer-facing forms to ease their effort in filling out the form.
A common use case for this is ‘report an issue’ forms. It’s important to make it easy for your customers to contact you, especially if the reason they’re reaching out is to report an issue.
In this tutorial, we’re going to walk through how to save your customers time and energy by building a form to report an issue that uses Populate Anything to automatically look up previous orders for the current user. Since WooCommerce requires users to create an account before placing an order, our form is going to automatically look up their previous orders and let them pick the product they’re reporting the issue on. Let’s get started!
This article assumes you have a fully set up WooCommerce store with some completed orders. Once you have GF Populate Anything installed, follow the steps below to build the form.
Step 1 – Orders Field Population and Filters
Start by adding a Drop Down field and populating it with completed WooCommerce orders for the currently-logged-in user. WooCommerce stores orders as Custom Posts, and Populate Anything’s filters give you granular control over what type of posts to populate.
Note the Post Status filter. WooCommerce uses custom post statuses to indicate what state the order is in. Completed orders are given the status
wc-completed. This status isn’t recognized by Populate Anything, so you’ll need to manually enter it using the Custom Value option in the filter drop down.
Step 2 – Choice Template for Orders Field
With the filters set up, the next step is to choose the Choice Template. Populate Anything defaults populate the Post ID as the value, which is perfect. For the label, I like to add the order total to remind customers exactly which order they’re selecting. This is a nice touch for customers that order from you often. You can populate multiple values into the label by selecting Custom Value from the drop down.
Here’s what it looks like on the front end:
Step 3 – Populate Products
With the Orders Drop Down finished, it’s time to populate the Products Drop Down. This time, the population will be directly from the WordPress database. WooCommerce stores the items from an individual order in the
prefix_woocommerce_order_items database table.
With those two fields in place, you add any other fields you want to include in your Report an Issue form. Here’s an example for how this form could look on the front end.
Taking It Further
Save yourself time finding the order by including a hidden field that populates with a link to the selected order. To do this, add a hidden Website field to the form, and set its Default Value to the WP Admin link for editing posts. The format for that link is the following:
Then, insert the Live Merge Tag for the Orders Drop Down above as the Post ID.
Here’s what that looks like in the field settings:
The URL will then show up in your entries on the back end.
:nohiddenmerge tag modifier.