How to Populate WooCommerce Order Data into Gravity Forms

Build a form for your customers to easily contact you regarding products they have ordered.

This article requires the GP Populate Anything perk.

Buy Gravity Perks to get this perk plus 47 other premium Gravity Forms plugins!

View Plugin Buy Gravity Perks

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!

Looking for a stronger Gravity Forms & WooCommerce integration? Check out Gravity Shop Product Configurator, which puts the control and customization of Gravity Forms inside WooCommerce products.

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

  1. Orders Field Population and Filters
  2. Choice Template for Orders Field
  3. Populate Products

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. A WooCommerce post status is required in order to get any results. 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.

The WooCommerce Status options are:

  • wc-processing: Payment has been received and the order is awaiting fulfillment.
  • wc-on-hold: Waiting to confirm payment.
  • wc-cancelled: The order is cancelled by the customer or an administrator.
  • wc-completed: The order is fulfilled and complete.

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.

To remove hidden fields from Confirmations and Notifications, use our All Fields Template and the :nohidden merge tag modifier.

Comments

  1. Peter
    Peter April 22, 2024 at 12:14 am

    Thank you for this helpful tutorial! I managed to populate a checkbox list of all ordered items of a specific order. However I’m struggling to add the Quantity of each product to the label (as this is another table in the database it seems) as well as to filter the list for specific product categories. E.g. I want to filter an order for all products of the category “fruits” and list them by name and quantity ordered in the form. Is there any workaround for this? Thanks a lot!

    Reply
    1. Scott Ryer
      Scott Ryer Staff April 22, 2024 at 1:34 pm

      Hi Peter,

      You can populate the quantity from the woocommerce_order_itemmeta table. Here’s a screenshot with an example setup:

      WC Order Item Quantity

      For the categories, WooCommerce doesn’t store that with the order. Drop us a line in support and we can look into what it would take to add support for this.

    1. Samuel Bassah
      Samuel Bassah Staff March 6, 2024 at 4:18 am

      Hi Revo,

      To get the quantity of the selected product, add a single line text field and set it up to populate data from the wp_woocommerce_order_itemmeta table. You’ll then add a filter to check if the order_item_id is equal to the value of the selected Product field. Add another filter to check if meta_key is equal to _qty to get the quantity. Set the value template property to the meta_value. This should get you the quantity of the selected product in the order.

      I hope this helps.

      Best,

  2. Ignatius
    Ignatius May 27, 2023 at 2:35 pm

    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.

    Reply
    1. David Smith
      David Smith Staff May 30, 2023 at 9:30 pm

      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!

  3. behy
    behy September 14, 2022 at 8:32 am

    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

    Reply
    1. Samuel Bassah
      Samuel Bassah Staff September 14, 2022 at 9:40 am

      Hi,

      You can use the placeholder setting of the field to add an empty text at the top of the populated choices.

      Best,

  4. اسماعیل منصوری
    اسماعیل منصوری July 31, 2021 at 3:36 am

    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.

    Reply
    1. Samuel Bassah
      Samuel Bassah Staff October 26, 2020 at 8:10 am

      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,

    2. Gaetan Ekszterowicz
      Gaetan Ekszterowicz October 26, 2020 at 12:24 pm

      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 ;).

Leave a Reply

Your email address will not be published. Required fields are marked *

  • Trouble installing this snippet? See our troubleshooting tips.
  • Need to include code? Create a gist and link to it in your comment.
  • Reporting a bug? Provide a URL where this issue can be recreated.

By commenting, I understand that I may receive emails related to Gravity Wiz and can unsubscribe at any time.

Grab a bundle of free Gravity Forms plugins

Enter your email and receive our most popular free plugins and snippets, plus access to hundreds of others.

This field is for validation purposes and should be left unchanged.