Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rvdsteege/1114efdba2e36946d54413b577f7d1b7 to your computer and use it in GitHub Desktop.
Save rvdsteege/1114efdba2e36946d54413b577f7d1b7 to your computer and use it in GitHub Desktop.
Pronamic Pay 2nd confirmation in Gravity Forms for successful payment based on entry values
/**
* Gravity Forms successful payment confirmation based on entry.
*/
add_filter( 'gform_confirmation', 'pronamic_gform_confirmation', 10, 4 );
function burometa_gform_confirmation( $confirmation, $form, $entry, $ajax ) {
// Setup.
$field_id = 14;
$field_value = 'recurring';
$custom_confirmation_id = '5c1b68379fc8x';
// Check payment.
$payment_id = gform_get_meta( $entry['id'], 'pronamic_payment_id' );
$payment = get_pronamic_payment( $payment_id );
if ( null === $payment ) {
return $confirmation;
}
// Check if payment has been completed.
if ( 'Success' !== $payment->get_status() ) {
return $confirmation;
}
// Check if entry value equals value from setup.
if ( $field_value !== $entry[ $field_id ] ) {
return $confirmation;
}
// Set custom confirmation.
$form = GFAPI::get_form( $entry['form_id'] );
if ( array_key_exists( $custom_confirmation_id, $form['confirmations'] ) ) {
remove_filter( 'gform_confirmation', 'pronamic_gform_confirmation', 10, 4 );
$form['confirmations'] = array_intersect_key(
$form['confirmations'],
array(
$custom_confirmation_id => true
)
);
$confirmation = GFFormDisplay::handle_confirmation( $form, $entry, $ajax );
add_filter( 'gform_confirmation', 'pronamic_gform_confirmation', 10, 4 );
}
// Return.
return $confirmation;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment