Use Text Fields as Customer Name

Maps plain text fields to be used as the customer name in the GP Bookings dashboard (Upcoming Bookings, etc.).

Credit: Gui Lamu

Instructions

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

  2. Update the $name_fields array below with your form ID and field IDs for first name and last name.

Code

Filename: gpb-use-text-fields-as-customer-name.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
42
43
<?php
/**
 * Gravity Perks // Bookings // Use Text Fields as Customer Name
 * https://gravitywiz.com/documentation/gravity-forms-bookings/
 *
 * Maps plain text fields to be used as the customer name in the
 * GP Bookings dashboard (Upcoming Bookings, etc.).
 *
 * Credit: Gui Lamu
 *
 * Instructions:
 *
 * 1. Install this snippet by following the steps here:
 *    https://gravitywiz.com/documentation/how-do-i-install-a-snippet/
 *
 * 2. Update the `$name_fields` array below with your form ID
 *    and field IDs for first name and last name.
 */
add_filter( 'gpb_customer_name', function( $name, $entry, $booking ) {
	if ( ! is_array( $entry ) ) {
		return $name;
	}

	// Update "1" to your form ID. Update "9" to your First Name field ID and "10" to your Last Name field ID.
	$name_fields = array(
		1 => array( 9, 10 ),
	);

	$form_id = (int) rgar( $entry, 'form_id' );
	if ( ! isset( $name_fields[ $form_id ] ) ) {
		return $name;
	}

	$parts = array();
	foreach ( $name_fields[ $form_id ] as $field_id ) {
		$value = trim( (string) rgar( $entry, (string) $field_id ) );
		if ( '' !== $value ) {
			$parts[] = $value;
		}
	}

	return ! empty( $parts ) ? implode( ' ', $parts ) : $name;
}, 10, 3 );

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.