The gform_stripe_cancel_url filter allows you to modify the Stripe session’s cancel URL, which is the URL users will be redirected to after canceling the payment on Stripe.
Usage
add_filter('gform_stripe_cancel_url', 'your_function_name', 10, 2);
Parameters
- $url (string) – The URL to be filtered.
- $form_id (int) – The ID of the form being submitted.
More information
See Gravity Forms Docs: gform_stripe_cancel_url
Examples
Change cancel URL for all forms
In this example, the cancel URL for all forms will be set to the specified page on your domain.
add_filter('gform_stripe_cancel_url', function($url, $form_id) { return 'https://your-domain.com/cancel-page'; }, 10, 2);
Change cancel URL for specific form
This example modifies the cancel URL for a specific form with an ID of 5.
add_filter('gform_stripe_cancel_url', function($url, $form_id) { if ($form_id == 5) { return 'https://your-domain.com/custom-cancel-page'; } return $url; }, 10, 2);
Add UTM parameters to the cancel URL
This example appends UTM parameters to the cancel URL for tracking purposes.
add_filter('gform_stripe_cancel_url', function($url, $form_id) { return $url . '?utm_source=stripe&utm_medium=cancel'; }, 10, 2);
Redirect users to a different domain
In this example, the cancel URL redirects users to a different domain.
add_filter('gform_stripe_cancel_url', function($url, $form_id) { return 'https://another-domain.com/cancel-page'; }, 10, 2);
Modify cancel URL based on user role
This example changes the cancel URL depending on the user’s role.
add_filter('gform_stripe_cancel_url', function($url, $form_id) { $user = wp_get_current_user(); if (in_array('administrator', $user->roles)) { return 'https://your-domain.com/admin-cancel-page'; } else { return 'https://your-domain.com/user-cancel-page'; } }, 10, 2);