The gform_stripe_success_url filter allows you to modify the success URL that users will be sent to after completing a payment with Stripe.
Usage
add_filter('gform_stripe_success_url', function($url, $form_id, $query) {
// Your custom code here
return $url;
}, 10, 3);
Parameters
- $url (string): The URL to be filtered.
- $form_id (int): The ID of the form being submitted.
- $query (string): The query string portion of the URL.
More information
See Gravity Forms Docs: gform_stripe_success_url
Examples
Change domain for localhost
In this example, the code changes the domain of the URL to your own domain if it is set to ‘localhost’:
add_filter('gform_stripe_success_url', function($url, $form_id, $query) {
GFCommon::log_debug(__METHOD__ . '(): Original URL: ' . $url);
// Replace example.com with your site domain
$url = str_replace('localhost', 'example.com', $url);
GFCommon::log_debug(__METHOD__ . '(): New URL: ' . $url);
return $url;
}, 10, 3);
Add a custom parameter to the success URL
In this example, the code adds a custom parameter (e.g., ‘payment_status=success’) to the success URL:
add_filter('gform_stripe_success_url', function($url, $form_id, $query) {
$url = add_query_arg('payment_status', 'success', $url);
return $url;
}, 10, 3);
Redirect to a specific page based on form ID
In this example, the code redirects the user to a specific page based on the form ID:
add_filter('gform_stripe_success_url', function($url, $form_id, $query) {
if ($form_id == 1) {
$url = 'https://example.com/page1';
} elseif ($form_id == 2) {
$url = 'https://example.com/page2';
}
return $url;
}, 10, 3);
Append form title to the success URL
In this example, the code appends the form title to the success URL:
add_filter('gform_stripe_success_url', function($url, $form_id, $query) {
$form = GFAPI::get_form($form_id);
$form_title = sanitize_title($form['title']);
$url = add_query_arg('form_title', $form_title, $url);
return $url;
}, 10, 3);
Redirect to a custom URL based on payment amount
In this example, the code redirects the user to a custom URL based on the payment amount:
add_filter('gform_stripe_success_url', function($url, $form_id, $query) {
$entry = GFAPI::get_entry($_POST['entry_id']);
$payment_amount = $entry['payment_amount'];
if ($payment_amount > 100) {
$url = 'https://example.com/high-value';
} else {
$url = 'https://example.com/regular-value';
}
return $url;
}, 10