Using Gravity Forms ‘gform_capsulecrm_opportunity’ PHP filter

The gform_capsulecrm_opportunity Gravity Forms PHP filter allows you to modify the Capsule CRM Opportunity object before it is created.

Usage

A generic example of using the filter:

add_filter('gform_capsulecrm_opportunity', 'your_function_name', 10, 4);

To target a specific form, append the form ID to the hook name:

add_filter('gform_capsulecrm_opportunity_1', 'your_function_name', 10, 4);

To target a specific feed for a form, append the form ID and feed ID to the hook name:

add_filter('gform_capsulecrm_opportunity_1_7', 'your_function_name', 10, 4);

Parameters

  • $opportunity (array): Capsule CRM opportunity object.
  • $form (Form Object): The current form.
  • $entry (Entry Object): The current entry.
  • $feed (Feed Object): The current feed.

More information

See Gravity Forms Docs: gform_capsulecrm_opportunity

Examples

Change Opportunity Description

Modify the opportunity description to ‘Opportunity Created by API’:

add_filter('gform_capsulecrm_opportunity', 'change_opportunity_object', 10, 4);

function change_opportunity_object($opportunity, $form, $entry, $feed) {
    $opportunity['description'] = 'Opportunity Created by API';
    return $opportunity;
}

Modify Opportunity Owner

Change the opportunity owner to a specific user:

add_filter('gform_capsulecrm_opportunity', 'modify_opportunity_owner', 10, 4);

function modify_opportunity_owner($opportunity, $form, $entry, $feed) {
    $opportunity['owner'] = array('username' => 'new_owner');
    return $opportunity;
}

Change Opportunity Name

Set the opportunity name based on the form field value:

add_filter('gform_capsulecrm_opportunity', 'set_opportunity_name', 10, 4);

function set_opportunity_name($opportunity, $form, $entry, $feed) {
    $opportunity['name'] = $entry[1]; // Assuming the name is stored in field ID 1
    return $opportunity;
}

Add Custom Milestone

Add a custom milestone to the opportunity:

add_filter('gform_capsulecrm_opportunity', 'add_custom_milestone', 10, 4);

function add_custom_milestone($opportunity, $form, $entry, $feed) {
    $opportunity['milestone'] = array('name' => 'Custom Milestone');
    return $opportunity;
}

Modify Opportunity Party

Change the opportunity party ID based on a form field value:

add_filter('gform_capsulecrm_opportunity', 'set_opportunity_party', 10, 4);

function set_opportunity_party($opportunity, $form, $entry, $feed) {
    $opportunity['party'] = array('id' => $entry[2]); // Assuming the party ID is stored in field ID 2
    return $opportunity;
}