Skip to content

Instantly share code, notes, and snippets.

@New0
Last active March 4, 2020 18:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save New0/3059d56e0277b556578f3e05faa500cd to your computer and use it in GitHub Desktop.
Save New0/3059d56e0277b556578f3e05faa500cd to your computer and use it in GitHub Desktop.
Dynamic plans in Braintree processor for Caldera Forms.
<?php
/**
* Plugin Name: CF Dynamic Braintree Plans
* Description: Set a different Braintree Plan ID based on a fields value, using one Braintree processor
* Author: New0
*/
/* Create a Dropdown select field and set the values of each otpion with the ID of a Braintree Plan. T
Then copy and paste this dropdown select field in the code below */
add_filter('caldera_forms_processor_value', function($value, $field, $args, $config, $form ){
//SET CORRECT FORM ID
$form_ID = "CF5e32b6d71e30b";
//SET SELECT FIELD ID USING PLAN IDs AS VALUES
$field_ID = "fld_2989660";
//Check if we are filtering the correct processor field in the correct form and the form is set with the correct dropdown field
if( $form['ID'] === $form_ID && isset($form['fields'][$field_ID]) && $field === "cf-braintree-plan-actual" ){
//Get the value of the Dropdown Select field
$plan_id = Caldera_Forms::get_field_data( $field_ID, $form );
//Set the fields value in the $config and return it as the value for the "cf-braintree-plan-actual" in the $data_object
$config["cf-braintree-plan-actual"] = $plan_id;
$value = $plan_id;
}
return $value;
}, 10, 5);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment