The gform_authorizenet_subscription_pre_create filter allows you to modify the subscription object before it’s sent to Authorize.net.
Usage
add_filter('gform_authorizenet_subscription_pre_create', 'your_function_name', 10, 5);
Parameters
- $subscription (object): The Authorize.net subscription object.
- $form_data (Form Data): An associative array containing the form title, billing address, payment amount, setup fee amount, line items created using the submitted pricing field values, and any discounts from coupons.
- $config (Authorize Net Config): The feed which is currently being processed.
- $form (Form Object): The form which is currently being processed.
- $entry (Entry Object): The entry which is currently being processed.
More information
See Gravity Forms Docs: gform_authorizenet_subscription_pre_create
Examples
Change startDate
Set the start date for a subscription. Authorize.net requires the startDate to be in the YYYY-MM-DD format.
add_filter('gform_authorizenet_subscription_pre_create', function ($subscription, $form_data, $config, $form, $entry) { if ($form['id'] != 30) { return $subscription; } $subscription->startDate = rgar($entry, '10'); return $subscription; }, 10, 5);
Change Trial Period Cycles
Set the Trial Period Cycles for a subscription.
add_filter('gform_authorizenet_subscription_pre_create', function ($subscription, $form_data, $config, $form, $entry) { if ($form['id'] != 30) { return $subscription; } $subscription->trialOccurrences = 15; return $subscription; }, 10, 5);
Add a Description
Set a description (up to 255 characters) for the subscription.
add_filter('gform_authorizenet_subscription_pre_create', function ($subscription, $form_data, $config, $form, $entry) { if ($form['id'] != 30) { return $subscription; } $subscription->orderDescription = 'This is my custom description...'; return $subscription; }, 10, 5);
Set the invoice number
Pass an entry value as the subscription invoice number.
add_filter('gform_authorizenet_subscription_pre_create', function ($subscription, $form_data, $config, $form, $entry) { if ($form['id'] != 1) { return $subscription; } $subscription->orderInvoiceNumber = rgar($entry, '46'); return $subscription; }, 10, 5);
Use Name field for subscription details
Use a Name field as the source for Authorize.net’s subscription details.
add_filter('gform_authorizenet_subscription_pre_create', function ($subscription, $form_data, $config, $form, $entry) { if ($form['id'] != 1) { return $subscription; } $subscription->first_name = rgar($entry, '1.3'); $subscription->last_name = rgar($entry, '1.6'); return $subscription; }, 10, 5);