Skip to content

Instantly share code, notes, and snippets.

@racmanuel
Created August 2, 2022 15:52
Show Gist options
  • Save racmanuel/dbdf6f4b0e8eb282fca4d8534c26e8d8 to your computer and use it in GitHub Desktop.
Save racmanuel/dbdf6f4b0e8eb282fca4d8534c26e8d8 to your computer and use it in GitHub Desktop.
remplace a list field of gravity forms with select and get the results from external api
<?php
add_filter( 'gform_column_input_2_15_1', 'set_column', 10, 5 );
function set_column( $input_info, $field, $column, $value, $form_id ) {
$request = wp_remote_get( 'https://pippinsplugins.com/edd-api/products' );
if( is_wp_error( $request ) ) {
return false; // Bail early
}
$body = wp_remote_retrieve_body( $request );
$data = json_decode( $body );
if( ! empty( $data ) ) {
foreach( $data->products as $product ) {
$products_array[] = $product->info->title;
}
}
return array(
'type' => 'select',
'choices' => $products_array,
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment