Last active
November 10, 2017 06:06
-
-
Save joshjenkinsAR/880ec155ab6260acfd3fb6391581df21 to your computer and use it in GitHub Desktop.
Save Authorize.net transaction id to gravity forms field after completed payment and include the new data in the Zapier feed
This file contains 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
/*** | |
* Add transaction ID to forms with this field after a payment is processed | |
***/ | |
add_action( 'gform_post_payment_action', 'save_transaction_id', 10, 2); | |
function save_transaction_id( $entry, $action ) { | |
$id = rgar( $entry, 'id'); | |
$trans_id = rgar( $action, 'transaction_id' ); | |
$trans_form_id = rgar( $entry, 'form_id'); | |
$trans_field_id = ''; | |
$form = GFAPI::get_form( $trans_form_id ); | |
foreach( $form['fields'] as $field ) { | |
if($field->label == 'Transaction ID'){ | |
$trans_field_id = $field->id; | |
} | |
} | |
GFAPI::update_entry_field( $id, $trans_field_id, $trans_id ); | |
} | |
/*** | |
* Add transaction field data to Zapier feed | |
***/ | |
add_filter( 'gform_zapier_field_value', 'format_entry_value', 10, 4 ); | |
function format_entry_value( $value, $form_id, $field_id, $entry ) { | |
$form = GFAPI::get_form( $form_id ); | |
foreach( $form['fields'] as $field ) { | |
if($field->label == 'Transaction ID'){ | |
$trans_field_id = $field->id; | |
} | |
} | |
if ( $field_id == $trans_field_id ) { | |
$entry = GFAPI::get_entry( $entry['id'] ); | |
$value = rgar( $entry, $trans_field_id ); | |
} | |
return $value; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment