Conditional Conferencing by Field Value

Only add conferencing (e.g. the Google Meet link) to a booking’s Google Calendar event when a chosen field matches an allowed value.

Instructions

  1. Install this snippet by following the steps here: https://gravitywiz.com/documentation/how-do-i-install-a-snippet/

  2. Update the three settings below to match your form.

Code

Filename: gpb-conditional-conferencing-by-field-value.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php
/**
 * Gravity Perks // Bookings // Conditional Conferencing by Field Value
 * https://gravitywiz.com/documentation/gravity-forms-bookings/
 *
 * Only add conferencing (e.g. the Google Meet link) to a booking's Google Calendar event when a
 * chosen field matches an allowed value.
 *
 * Instructions:
 *
 * 1. Install this snippet by following the steps here:
 *    https://gravitywiz.com/documentation/how-do-i-install-a-snippet/
 *
 * 2. Update the three settings below to match your form.
 */
add_filter( 'gpb_google_calendar_event_data', function( $event_data, $booking ) {

	// Configuration
	$form_id      = 123;            // Update '123' to your Form ID
	$field_id     = '4';            // Field ID that controls conferencing. Use a sub-field ID (e.g. '4.1') for multi-input fields.
	$field_values = array( 'Yes' ); // Update to the field value(s) that should add conferencing.

	if ( empty( $event_data['conferenceData'] ) ) {
		return $event_data;
	}

	$entry = $booking->get_entry();
	if ( ! $entry ) {
		return $event_data;
	}

	if ( (int) rgar( $entry, 'form_id' ) !== $form_id ) {
		return $event_data;
	}

	if ( ! in_array( (string) rgar( $entry, $field_id ), $field_values, true ) ) {
		unset( $event_data['conferenceData'] );
	}

	return $event_data;
}, 10, 2 );

Leave a Reply

Your email address will not be published. Required fields are marked *

  • Trouble installing this snippet? See our troubleshooting tips.
  • Need to include code? Create a gist and link to it in your comment.
  • Reporting a bug? Provide a URL where this issue can be recreated.

By commenting, I understand that I may receive emails related to Gravity Wiz and can unsubscribe at any time.