If you want to add WooCommerce/ ClassicCommerce products to a specific Gravity Forms form, add this snippet to your functions.php
// AUTO ADD CPT TITLES TO GFORM SELECT
add_filter( 'gform_pre_render_1', 'populate_posts' );
add_filter( 'gform_pre_validation_1, 'populate_posts' );
add_filter( 'gform_pre_submission_filter_1', 'populate_posts' );
add_filter( 'gform_admin_pre_render_1', 'populate_posts' );
function populate_posts( $form ) {
foreach ( $form['fields'] as &$field ) {
if ( $field->type != 'select' || strpos( $field->cssClass, 'populate-posts' ) === false ) {
continue;
}
// you can add additional parameters here to alter the posts that are retrieved
// more info: http://codex.wordpress.org/Template_Tags/get_posts
$posts = get_posts( 'post_type=product&posts_per_page=-1&orderby=name&order=ASC&post_status=publish' );
$choices = array();
foreach ( $posts as $post ) {
$choices[] = array( 'text' => $post->post_title, 'value' => $post->post_title );
}
// update 'Select a Post' to whatever you'd like the instructive option to be
$field->placeholder = 'Please select --';
$field->choices = $choices;
}
return $form;
}
In this context – 1 is the form ID and post_type=product is the product CPT.
Adapt as needed.