Gravity Perks // GP Unique ID // Generate Unique ID for PayPal Payments Pro Invoice
<?php
/**
* Gravity Perks // GP Unique ID // Generate Unique ID for PayPal Payments Pro Invoice Number
* http://gravitywiz.com/documentation/gp-unique-id/
*/
add_filter( 'gform_paypalpaymentspro_args_before_payment', function( $args, $form_id, $submission_data, $feed, $entry ) {
// remove filter that populates unique ID *after* entry is created
remove_filter( 'gform_entry_post_save', array( gp_unique_id()->field_obj, 'populate_field_value' ), 8, 2 );
$form = GFAPI::get_form( $form_id );
foreach( $form['fields'] as $field ) {
if( gp_unique_id()->field_obj->is_this_field_type( $field ) && ! GFFormsModel::is_field_hidden( $form, $field, array() ) ) {
$post_key = sprintf( 'input_%d', $field->id );
if( ! rgpost( $post_key ) ) {
$_POST[ $post_key ] = gp_unique_id()->get_unique( $form['id'], $field );
}
}
}
return $args;
}, 9, 5 );
add_filter( 'gform_paypalpaymentspro_args_before_payment', function ( $args, $current_form_id ) {
$form_id = 1343;
$field_id = 4;
if ( $current_form_id == $form_id ) {
$args['COMMENT1'] = rgpost( sprintf( 'input_%d', $field_id ) );
$args['INVNUM'] = rgpost( sprintf( 'input_%d', $field_id ) );
$args['COMMENT2'] = 'EMSpire';
}
return $args;
}, 10, 2 );