Last active
April 27, 2023 17:26
-
-
Save mwhiteley16/314b68ce0a79972128b7f31d8d1bb8fb to your computer and use it in GitHub Desktop.
Post Payment Gravity Forms
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
/** | |
* Update puppy reservation status after payment is received. | |
* | |
* @link https://docs.gravityforms.com/gform_after_submission/ | |
* | |
*/ | |
add_action( 'gform_post_payment_completed', 'wd_gform_submission_updates', 10, 2 ); | |
function wd_gform_submission_updates( $entry, $payment_id ) { | |
// Get form title of form that was submitted. | |
$form = GFAPI::get_form( $entry['form_id'] ); | |
$form_title = $form['title']; | |
// Update puppy reserved status when deposit is paid. | |
if( $form_title == 'Puppy Payments' ) { | |
// Get form data. | |
$puppy_id = (int) rgar( $entry, '9' ); | |
$user_first_name = rgar( $entry, '2' ); | |
$user_last_name = rgar( $entry, '3' ); | |
$user_name = $user_first_name . ' ' . $user_last_name; | |
// Update availability and reserved for fields. | |
if ( ! empty( $puppy_id ) ) { | |
update_field( 'availability', 'reserved', $puppy_id ); | |
update_field( 'reserved_for', $user_name, $puppy_id ); | |
// Flush out page cache to show proper status (WP Rocket). | |
if ( function_exists( 'rocket_clean_post' ) ) { | |
rocket_clean_post( $puppy_id ); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment