Using Gravity Forms ‘gform_ppcp_discount_total’ JavaScript filter

The gform_ppcp_discount_total Gravity Forms JavaScript filter is used to override the discount amount that will be sent to PayPal Checkout.

Usage

A generic example of how to use the filter for all forms:

gform.addFilter('gform_ppcp_discount_total', function(discountTotal, formId, total) {
    // your custom code here
    return discountTotal;
}, 10, 3);

Parameters

  • discountTotal (float): The calculated positive discount total value.
  • formId (int): The ID of the current form.
  • total (float): The form total value.

More information

See Gravity Forms Docs: gform_ppcp_discount_total

Examples

Log the parameters

This example logs the contents of the three parameters to the browser console.

gform.addFilter('gform_ppcp_discount_total', function(discountTotal, formId, total) {
    console.log(arguments);
    return discountTotal;
}, 10, 3);

Apply a 10% discount

This example applies a 10% discount to the total.

gform.addFilter('gform_ppcp_discount_total', function(discountTotal, formId, total) {
    var newDiscount = total * 0.1;
    return newDiscount;
}, 10, 3);

Set a fixed discount amount

This example sets a fixed discount amount of $20.

gform.addFilter('gform_ppcp_discount_total', function(discountTotal, formId, total) {
    return 20;
}, 10, 3);

Apply discount based on form ID

This example applies a 5% discount for form ID 1 and a 10% discount for form ID 2.

gform.addFilter('gform_ppcp_discount_total', function(discountTotal, formId, total) {
    if (formId === 1) {
        return total * 0.05;
    } else if (formId === 2) {
        return total * 0.1;
    } else {
        return discountTotal;
    }
}, 10, 3);

No discount for totals below $50

This example removes the discount if the total is below $50.

gform.addFilter('gform_ppcp_discount_total', function(discountTotal, formId, total) {
    if (total < 50) {
        return 0;
    } else {
        return discountTotal;
    }
}, 10, 3);