Last active
April 16, 2024 10:17
-
-
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.
This file contains hidden or 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
<?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