Skip to content

Instantly share code, notes, and snippets.

@samuelaguilera
Last active July 25, 2025 14:21
Show Gist options
  • Select an option

  • Save samuelaguilera/231d8e4576c9f2190892b980dcc0cb62 to your computer and use it in GitHub Desktop.

Select an option

Save samuelaguilera/231d8e4576c9f2190892b980dcc0cb62 to your computer and use it in GitHub Desktop.
Send total without discount
<?php
// NOTE: THE CODE TO COPY/PASTE STARTS BELOW THIS LINE
/**
* Undo the coupon discount for Stripe subscription feeds.
*
* It assumes only one coupon is being applied.
*
* You need to update the form id number in the filter name line and the Total field id in the variable for it.
*
* @version 1.0
*
*/
add_filter(
'gform_submission_data_pre_process_payment_2669', // Change 2669 to your form id.
function ( $submission_data, $feed, $form, $entry ) {
gf_stripe()->log_debug( __METHOD__ . '(): running.' );
if ( defined( 'GF_STRIPE_VERSION' ) && version_compare( GF_STRIPE_VERSION, '6.0', '>=' ) ) {
gf_stripe()->log_debug( __METHOD__ . '(): Stripe 6.0 or newer...' );
return $submission_data;
}
$transactiontype = rgars( $feed, 'meta/transactionType' );
if ( $transactiontype != 'subscription' ) {
gf_stripe()->log_debug( __METHOD__ . '(): Skipping... Not a subscription feed: ' . $transactiontype );
return $submission_data;
}
// Change 8 in the following line to your Total field id number.
$total_field_id = 11;
gf_stripe()->log_debug( __METHOD__ . '(): Total amount: ' . rgar( $entry, $total_field_id ) );
// Skip if the Coupon add-on is not enabled.
if ( ! class_exists( 'GFCoupons' ) ) {
gf_stripe()->log_debug( __METHOD__ . '(): Coupons add-on is not enabled.' );
return $submission_data;
}
$product_info = GFCommon::get_product_fields( $form, $entry );
$coupon_field = ( new GFCoupons() )->get_coupon_field( $form );
// Skip if no coupon was used for this submission, not a subscription, or not a Stripe feed.
if ( empty( $coupon_field ) || $feed['meta']['transactionType'] != 'subscription' || $feed['addon_slug'] != 'gravityformsstripe' ) {
gf_stripe()->log_debug( __METHOD__ . '(): Skip if no coupon was used for this submission, not a subscription, or not a Stripe feed.' );
return $submission_data;
}
$coupon_codes = ( new GFCoupons() )->get_submitted_coupon_codes( $form, $entry );
gf_stripe()->log_debug( __METHOD__ . '(): Coupon codes: ' . print_r( $coupon_codes, true ) );
if ( is_array( $coupon_codes ) ){
foreach ( $coupon_codes as $code ) {
$coupon_price = substr( $product_info['products'][ $coupon_field->id . '|' . $code ]['price'], 1 );
gf_stripe()->log_debug( __METHOD__ . '(): Coupon amount: ' . $coupon_price );
}
}
// Undo the coupon discount.
$submission_data['payment_amount'] = rgar( $entry, $total_field_id ) + $coupon_price;
gf_stripe()->log_debug( __METHOD__ . '(): Amount before discount passed to Stripe: ' . $submission_data['payment_amount'] );
return $submission_data;
},
10,
4
);
@kennys74

kennys74 commented Feb 20, 2018

Copy link
Copy Markdown

Hi there. I'm not sure the code above is 100% correct Samuel. I've tested this now on our site: www.register.za.com. If I declare this variable: $total_field = rgar( $entry, '13' ) it equals the new total including the discount. My total field ID is 13. It needs pass the total prior to the discount which on our form is a hidden form field with a name: "gf_total_no_discount_2". How would I get this variable from calling rgar() function?

Many thanks

Ken

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment