The gform_ppcp_intent filter in the Gravity Forms PayPal Checkout Add-On allows the payment intent to be overridden.
Usage
add_filter('gform_ppcp_intent', 'your_function_name', 10, 3);
Parameters
- $intent (string): The payment intent. Default is ‘capture’. Possible values: ‘capture’ or ‘authorize’.
- $form_id (int): The ID of the current form.
- $feed_id (int): The ID of the current feed.
More information
See Gravity Forms Docs: gform_ppcp_intent
Examples
Change payment intent to ‘authorize’
This example changes the payment intent to ‘authorize’ instead of the default ‘capture’.
add_filter('gform_ppcp_intent', 'change_intent', 10, 3);
function change_intent($intent, $form_id, $feed_id) {
return 'authorize';
}
Change payment intent based on form ID
This example changes the payment intent to ‘authorize’ for a specific form ID.
add_filter('gform_ppcp_intent', 'change_intent_based_on_form', 10, 3);
function change_intent_based_on_form($intent, $form_id, $feed_id) {
if ($form_id == 5) {
return 'authorize';
}
return $intent;
}
Change payment intent based on total amount
This example changes the payment intent to ‘authorize’ if the total amount is greater than 1000.
add_filter('gform_ppcp_intent', 'change_intent_based_on_amount', 10, 3);
function change_intent_based_on_amount($intent, $form_id, $feed_id) {
$total = GFFormsModel::get_form_total($form_id, $_POST);
if ($total > 1000) {
return 'authorize';
}
return $intent;
}
Change payment intent based on user role
This example changes the payment intent to ‘authorize’ for users with a specific role.
add_filter('gform_ppcp_intent', 'change_intent_based_on_user_role', 10, 3);
function change_intent_based_on_user_role($intent, $form_id, $feed_id) {
$current_user = wp_get_current_user();
if (in_array('administrator', $current_user->roles)) {
return 'authorize';
}
return $intent;
}
Change payment intent based on custom field value
This example changes the payment intent to ‘authorize’ if a custom field value is equal to a specific value.
add_filter('gform_ppcp_intent', 'change_intent_based_on_custom_field', 10, 3);
function change_intent_based_on_custom_field($intent, $form_id, $feed_id) {
$custom_field_value = rgpost('input_7');
if ($custom_field_value == 'authorize_payment') {
return 'authorize';
}
return $intent;
}