Skip to content

Instantly share code, notes, and snippets.

@thelevicole
Created February 13, 2023 15:24
Show Gist options
  • Save thelevicole/355a48bf34cf5dd03fc219b3300f9c09 to your computer and use it in GitHub Desktop.
Save thelevicole/355a48bf34cf5dd03fc219b3300f9c09 to your computer and use it in GitHub Desktop.
Add GCLID ($gclid) property to GravityForms Zoho lead
<?php
add_filter( 'gform_zohocrm_lead', function( $lead, $feed, $entry, $form ) {
$gclid_keys = [ '$gclid', 'GCLID' ];
$custom_fields = !empty( $feed[ 'meta' ][ 'leadCustomFields' ] ) ? $feed[ 'meta' ][ 'leadCustomFields' ] : null;
if ( $custom_fields && is_array( $custom_fields ) ) {
foreach( $custom_fields as $custom_field ) {
$key = rgar( $custom_field, 'key' );
$value = rgar( $custom_field, 'value' );
$custom_key = rgar( $custom_field, 'custom_key' );
$custom_value = rgar( $custom_field, 'custom_value' );
if ( $key === 'gf_custom' ) {
if ( in_array( $custom_key, $gclid_keys ) ) {
$lead[ '$gclid' ] = $custom_value;
}
} else {
if ( in_array( $key, $gclid_keys ) ) {
$lead[ '$gclid' ] = rgar( $entry, $value );
}
}
}
}
return $lead;
}, 10, 4 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment