Had an interesting question on the forum today:
- The site has multiple publications that are available for purchase, each has a separate price value. The rest of the form is the same for each publication, only the price changes.
- I want all publications to be purchased using a singular form.
- I want the variation in price controlled by a custom field in WordPrss.
Does that sound possible?
For developers familiar with Gravity Forms, the first tool you might reach for is Dynamic Population using the gform_field_value hook. That will work, but here is an easier method.
Using Merge Tags with Dynamic Population
If you’ve used Gravity Forms before, you’re probably familiar with merge tags. Merge tags allow you to include information specific to the current form, entry, user, page, post and much more! Product fields don’t support the default value option so we’ll need to enable dynamic population for this field.

You will see that I am using the {embed_post:post_title}
merge tag with the “post_title” property. This will display the current post/page title as the product name. You can add the same form on multiple posts and this merge tag will always output the title of the post on which the form is currently being viewed.
Next, we’re using the {custom_field:price}
to populate the post’s custom field titled “price” for the Product field’s “price” input. This assumes you have already setup a custom field on each post named “price”. Whatever value is stored for this custom field (in my example below, the value is “16.99”) will be populated for the field input you’ve indicated. We use the same method to populate the quantity input as well.

Wait… I didn’t think you could use merge tags as population parameters?
Gravity Forms does not support using merge tags as dynamic population parameters out of the box but I’ve written a little snippet that makes these work automagically!
Just paste this code in your theme’s functions.php file.
Summary
The finished product (no pun intended) will be a product that is completely populated from custom fields (aka post meta).
This is just one example of how enabling merge tags for dynamic population can be used. Are you planning on using this for something else? Tell us about it in the comments.
Did this resource help you do something awesome with Gravity Forms? Then you'll absolutely love Gravity Perks; a suite of 39+ essential add-ons for Gravity Forms with support you can count on.
Not sure if this is the method we need. We have a custom quote form (not completed). There are multiple products. Each product has different specs like size, material, etc.. These options will appear using conditional logic I am assuming depending on product selected. Each spec has a different price. My first dilemma is how to allow for selecting multiple products since each one has a different set of specs to be chosen from. Second dilemma, how to allow user to select multiple products and obtain a correct total no matter what product or how many is chosen. I do know that I will need the value from a main quantity field passed onto the selections for specs. Then all specs will be multiplied by the main total number value. The page is multi page. I’m new to GF. I understand dynamic content, but not sure of the best method to use. Any help greatly appreciated!
Hi Derrick, I’m not sure I fully understand your requirements. They sound complex enough that hiring a GF developer to offer some consultation might be a good idea.
Hi David,
Just wanted to say thanks for this tutorial, it was just what I was looking for when building a virtual gift shop for a charity website.
Ben
Awesome, Ben! Glad we could help. :)
Hi David
Thanks for this. It’s going to be perfect on a site I’m developing selling training courses. Now I can set up posts with the course title as the post title, add a custom Price field, and then populate a form based on that data and send it to the GF PayPal add-on. One form can be used across however many courses are running, rather than having to do a new form for each course.
Love your site. It’s helped me a ton.
Thanks Dom
Dom, you rock! Awesome use case. :)
Thanks a LOT David for the code, works perfectly and saved me loads of time. Cheers!
Glad we could help!
Is there any way to dynamic populate the differents values for a dropbox, based on a previous selection (in a diferent field) in the same form?
For example: I select the tshirt color in dropbox one, so in the second dropbox I want to dynamic populate all the available sizes for that selected color.
thanks.
Hi Mariano, chained selects (which is what this feature is called) is coming to Gravity Forms very soon. In the meantime, you can pick up a copy of this plugin: https://gravityplus.pro/gravity-forms-dynamic-population/
Thanks, I guess I’ll wait. :)
So there is no snippets for a workarround…:(
Mariano
Gravity forms dynamic population works well but you have to notice that it does not work today with multipage forms. Also, you will have to create in your database a simple table with the columns of your choice containing the data to be chained column by column. Don’t be afraid it is just a few easy lines of code that you can easily find on mysql documentation.
Sweet. I needed to display a form on several different pages but each form needed to be directly linked to the page it was on. I used the {embed_post:post_title} tag to pull in the post title into a hidden field so I can see which form is submitted.
A life saver because I thought I was going to have to create 100’s of different forms for each page on my site.
Thanks a lot
Neil
This is an awesome use-case, Neil! Thanks for sharing. :)
Very cool. Thank you so much for this code!!!! Worked beautifully with my project. Integrated Gravity forms with Woocommerce data. Thank you. Where is a donate button ?
Hi Carlos, best way to say thank you is buying Gravity Perks. If that’s a bigger “thank you” then you were planning, just wait a little while and I’m sure you’ll either use another one of my snippets or need to buy Gravity Perks for one of it’s many features. ;)
Regardless, I’m happy to have been able to help you!
I’m trying to populate a product’s quantity field with a calculation (number field). Does it work with this? I have tried but no luck so far.
Hi Liam, you can use GP Copy Cat to populate the value of Calculation field into the Quantity input (example) and you can use GP Read Only to make the Quantity input read-only. Chances are, you won’t want the Calculated field to be visible. You can hide it by adding the “gf_hidden” class to the “Custom CSS Class” setting via the Form Editor.
Hi David,
Great site, I’m also a massive fan of Gravity Forms!
I’m using this at the monent on our product pages and want to direct the form submission to different email addresses based on the url it was submitted from.
So in the ‘send to’ and ‘configure routing’ options I’m saying send to example@example.com if ‘hidden field’ is ….
What do I need to put as the variable; the full URL, the page ID, or something else? I’ve tried the full url and page ID on our test server but the email doesn’t seem to be coming through to the email address I’ve specified.
Thanks
You could capture the {embed_url} which will allow you to base the the routing on which page the form is coming from. :)
Hello david,
In first time I’m loving your site!
I have a similar situation, I think..
I want to display a field based on a hidden field that dynamically recovered the value of a dropdown field in front of the gravity form.
If hidden field get dropdown variation 1 => display section 1 if hidden field get dropdown variation 2 => display section 2
Thanks for your help!!
Hi Steph, glad you’re loving the site. :)
I’m not sure I understand what you’re trying to do. Could you clarify? A screengrab or demo site would be welcome.
Hey David!
First off, I’m loving this site!
I have a situation similar to the original question in this post, but I just need the {embed_post:post_title} to work. I copied the code into my functions.php, created a hidden field in the form, added “allow field to be populated dynamically”, and added {embed_post:post_title} as the parameter. Upon looking at the entries, though, the data is not getting passed on to the form entry.
I just need the post title to be collected on a form that is across multiple posts. I am already collecting the author_name so that proper notifications are getting sent, but I’d like to further sort this out so that if one author has multiple posts, they will be able to see the title of the post that the form entry came from.
Thanks for any help!!!
I would expect this to work as well. You may have found a bug. I’d ping GF support to get this confirmed.
Thanks for your reply! In beginning to submit a ticket, I had to check my GF version and realized that on the site I’m using to test, I had not updated the plugin in a good while. IDIOT!
Anyway, the snippet works beautifully now!
Do you have a list of all the meta items this would work with?
Thanks again for your help!!!
It will work with any pre pop merge tag (you can get a list by checking out the merge tag icon next to the Default Value setting of most fields). It will also work with {user:any_custom_meta_key} and probably some more that I’m not thinking about right now… A lot!
Hi there, I have a similar problem I’ve been trying to solve: We sell memberships for water polo 4x year Each parent registers and signs up one or more of their children. During the course of the season the child must register and pay for various tournaments (products in WC) The problem I am try to solve is populating the child information EACH time a parent is required to register for or pay for a tournament. * using UserMetaMgr I am able to store an expanded profile of the children in the user meta.
It would appear that I could us GF to populate a field with custom user meta
Is it possible to pre-populate a dropdown with the multiple children in GF that can be associated with the WC order?
Sorry for posting a reply to your original post, it however seems relevant. Thanks Joel
Hi Joel,
It’s possible but would require custom code. Here is a good article on how to populate drop down fields. In your case, rather than use
get_posts()
to populate posts, you’d need to use the GFAPI::get_entries() method to fetch the original entry submitted by this user from the original form and then loop through those entries to get the names of the children.Thank you very much for this! I used your function in a project I’m currently working on. It made life so much easier!
I’m stoked you were able to use this! Thanks for letting me know. :)
RE comment on October 1, 2014 at 6:41 am
I am also looking for my form to be prepopulated with the product attributes of the product for which the form is shown, so that when the form is submitted the product which has been created has carried over those attributes – attributes being a feature of WooCommerce but which are shown in the metadata as what I assume is an array, for example:
_product_attributes pa_manufacturer » name pa_manufacturer » value » position 50 » is_visible 1 » is_variation 0 » is_taxonomy 1
How would I call these from my form?
Thanks
Stuart
Hey Stuart, I’m not familiar with how this would be handled. A WC expert would be better equipped to answer this questions. If anyone else knows, please feel free to jump in. :)
Hi Wiz- I’m getting an error with this snippet that gives me the white screen of nothing. I assume that it’s because I just added your more recent snippet so I can use Merge Tags in my Confirmation page. I deduced this from my error log:
PHP Fatal error: Cannot redeclare gw_prepopluate_merge_tags()
Are they mutually exclusive?
There shouldn’t be any interference with the Post Content Merge Tags snippet. That’s all wrapped in it’s own class so none of the functions would cause this issue. If you search for that function name “gw_prepopluate_merge_tags” in your theme’s functions.php do you see any other instances of it?
thanks for the snippet, worked well.
Is there a way of dynamically populating from the product attributes.
Thanks
mark
Hi Mark, I’m not sure I understand. Could you elaborate?
Is there a way to pre-populate a form based on the contents of a previously-submitted form? The use case would be, admin wants to send a link to the form submitter to review and/or update their previous submission. Feel free to email me if you have a solution — even if it would there would be a price associated ;)
Hey Dave, saw your query on Twitter first and just responded to your email.
For others looking for the same functionality, I am working on a more robust solution which will be available here at GravityWiz.com soon. :)
Hi David. I’m new with Gravity Forms. I have created two forms to fill two tables created with MYSQL Table Builder (add-on) in the database. That’s all ok, but I want a field on one form is filled dynamically from a ‘select’ field type, containing data from another field in the other table. Imagine: A table ‘books’ and other ‘readings’. Therefore the ‘readings’ table field ‘book_name’, could be filled from ‘select’ type field, where all the books, by its name, appear. I have some knowledge of PHP, and I guess I should use ‘gform_field_value_list’, but do not know how. Thank you very much, from Spain.
Osvaldo
Hi Osvaldo,
Here is a tutorial which covers the basics of populating a select field (aka drop down).
http://www.gravityhelp.com/documentation/page/Dynamically_Populating_Drop_Down_Fields
This tutorial demonstrates how to retrieve and populate a list of posts. In your case, you would need to query your custom table and populate that data instead. This tutorial will cover the format that the data needs to be in and here is some WordPress documentation on using the $wpdb (wordpress database object) to assist in writing custom queries. This assumes that your custom table is in the same database as your WP install.
http://codex.wordpress.org/Class_Reference/wpdb
Hi David — is there an easy way to use this snippet to dynamically pull into user data beyond first and last name? I’d like to be able to dynamically pull in other “standard” WP fields from the user’s profile. Thanks in advance for any pointers …
Cheers, Chris
{user:xxx}
should work for any user meta. For example, the email is “user_email” and the merge tag would be{user:user_email}
.Hi David — thanks for the quick response. I should have been clearer in my question :-)
I have a number of custom fields that have been added by (in this case) Wishlist Member. I’d like to be able to dynamically call them.
For example: from the following array, I’d like to be able to pull wpm_useraddress[company]
[wpm_useraddress] => Array ( [company] => [address1] => [address2] => [city] => [state] => [zip] => [country] => Select Country )
Thanks for any further pointers!
Cheers, Chris
There isn’t an easy way I know of to do this. You’d need to write some custom code that handles getting the “nested” value.
Hi David — thanks; if, instead I added a custom field to the user’s profile (using CIMY User Profile plugin), is there a change to your snippet that would allow me to dynamically call that field (i.e., not in an array) into the Gravity Form?
Thanks for your help — feel free to email me if this is complex and we can chat about (more) paid work.
Thanks, Chris
Sent you an email. :)