Created
January 22, 2021 16:14
-
-
Save ZachWatkins/de046890f7859ee89aefb5a0bd63bf18 to your computer and use it in GitHub Desktop.
Gravity Forms Single Product Field Error
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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