<?php
/**
* Update ACF meta after successful payment
*
* @link https://docs.gravityforms.com/gform_post_payment_completed/
*
*/
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 based on form title (can also use form ID)
if( $form_title == 'Name of Form' ) {
// Get form data.
$form_sub_id = (int) rgar( $entry, '1' ); // ID to update (int)
$form_field_1 = rgar( $entry, '2' );
// Update availability and reserved for fields.
if ( ! empty( $form_sub_id ) ) {
update_field( 'field_key', 'value', $form_sub_id );
// Flush out page cache to show proper status (WP Rocket).
if ( function_exists( 'rocket_clean_post' ) ) {
rocket_clean_post( $form_sub_id );
}
}
}
}