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/d3ca3af59e7ef1800eca22d206808681 to your computer and use it in GitHub Desktop.
Save rvdsteege/d3ca3af59e7ef1800eca22d206808681 to your computer and use it in GitHub Desktop.
Update Formidable Forms field in entry when payment status of a Pronamic Pay payment is updated.
<?php
/**
* Update Formidable Forms field in entry when payment status of a Pronamic Pay payment is updated.
*/
add_action( 'pronamic_payment_status_update_formidable-forms', 'pronamic_pay_update_formidable_forms_entry_payment_status' );
function pronamic_pay_update_formidable_forms_entry_payment_status( $payment ) {
/**
* Form fields to update with payment status.
*
* Format: Form ID => ID of field to update with status.
*/
$fields = array(
2 => 413,
);
// Check if Formidable Forms classes are available.
if ( ! class_exists( '\FrmEntry' ) || ! class_exists( '\FrmEntryMeta' ) ) {
return;
}
// Get entry.
$entry_id = $payment->get_source_id();
$entry = FrmEntry::getOne( $entry_id );
if ( empty( $entry ) ) {
return;
}
// Check if field to update has been specified for this form.
if ( ! \array_key_exists( $entry->form_id, $fields ) ) {
return;
}
// Go ahead, update the field with payment status.
$updated = FrmEntryMeta::update_entry_meta( $entry_id, $fields[ $entry->form_id ], null, $payment->get_status_label() );
if ( ! $updated ) {
FrmEntryMeta::add_entry_meta( $entry_id, $fields[ $entry->form_id ], null, $payment->get_status_label() );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment