The gform_stripe_subscription_cancel_at_period_end Gravity Forms PHP filter can be used to delay the cancellation of a subscription until the end of the current period.
Usage
A generic example of how to use the filter:
add_filter('gform_stripe_subscription_cancel_at_period_end', 'your_function_name', 10, 3);
Parameters
- $at_period_end (bool): Defaults to false, subscription will be cancelled immediately.
- $entry (Entry Object): The entry from which the subscription was created.
- $feed (Feed Object): The feed object which processed the current entry.
More information
See Gravity Forms Docs: gform_stripe_subscription_cancel_at_period_end
Examples
Apply to all subscriptions
Delay cancellation for all subscriptions:
add_filter('gform_stripe_subscription_cancel_at_period_end', '__return_true');
Apply to a specific feed
Delay the subscription cancellation for a specific feed by checking the feed name:
add_filter('gform_stripe_subscription_cancel_at_period_end', 'stripe_subscription_cancel_at_period_end', 10, 3); function stripe_subscription_cancel_at_period_end($at_period_end, $entry, $feed) { $feed_name = rgars($feed, 'meta/feedName'); if ($feed_name == 'your feed name here') { return true; } return $at_period_end; }
Apply based on a specific form field
Delay the subscription cancellation based on a specific form field value:
add_filter('gform_stripe_subscription_cancel_at_period_end', 'stripe_subscription_cancel_based_on_field', 10, 3); function stripe_subscription_cancel_based_on_field($at_period_end, $entry, $feed) { $field_value = rgar($entry, '1'); // Change '1' to your field ID if ($field_value == 'your desired value') { return true; } return $at_period_end; }
Apply to subscriptions with a specific product
Delay the subscription cancellation for a specific product by checking the product name:
add_filter('gform_stripe_subscription_cancel_at_period_end', 'stripe_subscription_cancel_based_on_product', 10, 3); function stripe_subscription_cancel_based_on_product($at_period_end, $entry, $feed) { $product_name = rgar($entry, '2'); // Change '2' to your product field ID if ($product_name == 'your product name here') { return true; } return $at_period_end; }
Apply based on user role
Delay the subscription cancellation based on the user role:
add_filter('gform_stripe_subscription_cancel_at_period_end', 'stripe_subscription_cancel_based_on_user_role', 10, 3); function stripe_subscription_cancel_based_on_user_role($at_period_end, $entry, $feed) { $user_id = rgar($entry, 'created_by'); $user = get_userdata($user_id); if (in_array('your_role_here', (array) $user->roles)) { return true; } return $at_period_end; }