This article requires the GP Populate Anything perk.
Buy Gravity Perks to get this perk plus 46 other premium Gravity Forms plugins!
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!
Getting 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.
Steps
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.
That’s It!
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:
https://your.site/wp-admin/post.php?post=123&action=edit
Then, insert the Live Merge Tag for the Orders Drop Down above as the Post ID.
https://your.site/wp-admin/post.php?post=@{:3:value}&action=edit
Here’s what that looks like in the field settings:
The URL will then show up in your entries on the back end.
:nohidden
merge tag modifier. Did this resource help you do something awesome with Gravity Forms?
Then you'll absolutely love Gravity Perks; a suite of 46+ essential add-ons for Gravity Forms with support you can count on.
Hey,
Thanks for your article !
I’m using {post:post_date} to get WooCommerce order date, do you know how to remove timestamp from date format ? I tried to use date(‘Y-m-d’, strtotime({post:post_date})) inside Choice Template label but do not work.
Best Regards.
We don’t have a ready solution for this one but, if you’re a Pro customer, it seems like something we could cover as a minor customization. Drop us a line via support!
With regards, how can I create an unbreakable space in Popular Aniting to leave the first option of the drop-down field empty, please guide me clearly. Thanks
Hi,
You can use the placeholder setting of the field to add an empty text at the top of the populated choices.
Best,
Important Tips: WooCommerce 3.5 began storing the customer ID associated with an order in the post_author field of the wp_posts table. Previously, this information was stored in post meta as _customer_user, and will continue to be stored there as well for backwards compatibility.
Thanks for sharing this tip.
Best,
Guys, finding orders this way doesn’t work at all! This is no longer a post type. That’s the only one reason I chose your GP. Please help us, we need it asap. Here is our website https://association.confidencesdabeilles.fr/
thanks for letting me know it dont work i was just about to pay for it :(
Hi Shawn,
We’re replying to Gaetan via email, to see how best we can assist with his use case. You can also get in touch via our pre-sales contact form with details about your use case. With that, we’ll be able to determine if what you want to achieve is possible or not.
Best,
To be accurate Shawn and for the others. We’re using Woocommerce subscriptions and this is precisely that plugin which causes some issues. We, and thanks to the very helpful Samuel, were able to identify it. I’m sure it works as a charm for the normal wordpress ecommerce! Give it a try, it’s the only way to know ;).