Skip to content

Instantly share code, notes, and snippets.

@ZachWatkins
Created January 22, 2021 16:14
Show Gist options
  • Save ZachWatkins/de046890f7859ee89aefb5a0bd63bf18 to your computer and use it in GitHub Desktop.
Save ZachWatkins/de046890f7859ee89aefb5a0bd63bf18 to your computer and use it in GitHub Desktop.
Gravity Forms Single Product Field Error
// Get order form.
$form = \GFAPI::get_form( 1 );
// Get next form field ID.
$new_field_id = 0;
foreach( $form['fields'] as $field ) {
if( $field->id > $new_field_id ) {
$new_field_id = $field->id;
}
}
$new_field_id++;
//create an array of field properties, this example creates a text field
//pass array to the create method
$properties = array();
$properties['type'] = 'product';
$field = \GF_Fields::create( $properties );
$field->id = $new_field_id;
$field->label = 'My New Field';
$field->inputType = 'singleproduct';
// Add the new field to the form.
$form['fields'][] = $field;
// Save the modified form.
\GFAPI::update_form( $form );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment