Using Gravity Forms ‘gform_paypal_business_email’ PHP filter

The gform_paypal_business_email filter allows you to modify the PayPal business email while validating the IPN from PayPal.

Usage

add_filter('gform_paypal_business_email', 'your_function_name', 10, 3);

Parameters

  • $paypalEmail (string): The PayPal email.
  • $feed (Feed Object): The current feed.
  • $entry (Entry Object): The current entry.

More information

See Gravity Forms Docs: gform_paypal_business_email

Examples

Change PayPal Business Email

This example changes the PayPal business email to ‘[email protected]‘.

add_filter('gform_paypal_business_email', 'change_email', 10, 3);
function change_email($paypalEmail, $feed, $entry) {
    $paypalEmail = '[email protected]';
    return $paypalEmail;
}

Use a Different Email Based on Form ID

This example changes the PayPal business email based on the form ID.

add_filter('gform_paypal_business_email', 'change_email_by_form_id', 10, 3);
function change_email_by_form_id($paypalEmail, $feed, $entry) {
    if ($entry['form_id'] == 1) {
        $paypalEmail = '[email protected]';
    } elseif ($entry['form_id'] == 2) {
        $paypalEmail = '[email protected]';
    }

    return $paypalEmail;
}

Update PayPal Email Based on User Role

This example changes the PayPal business email based on the user role.

add_filter('gform_paypal_business_email', 'change_email_by_user_role', 10, 3);
function change_email_by_user_role($paypalEmail, $feed, $entry) {
    $user = get_user_by('id', $entry['created_by']);

    if (in_array('administrator', $user->roles)) {
        $paypalEmail = '[email protected]';
    } else {
        $paypalEmail = '[email protected]';
    }

    return $paypalEmail;
}

Set PayPal Email Based on Product Category

This example changes the PayPal business email based on the product category.

add_filter('gform_paypal_business_email', 'change_email_by_category', 10, 3);
function change_email_by_category($paypalEmail, $feed, $entry) {
    $product_category = rgar($entry, '3'); // Replace '3' with the field ID of the product category.

    if ($product_category == 'Electronics') {
        $paypalEmail = '[email protected]';
    } elseif ($product_category == 'Clothing') {
        $paypalEmail = '[email protected]';
    }

    return $paypalEmail;
}

Conditionally Modify PayPal Business Email

This example changes the PayPal business email if the total amount is greater than 100.

add_filter('gform_paypal_business_email', 'change_email_based_on_amount', 10, 3);
function change_email_based_on_amount($paypalEmail, $feed, $entry) {
    $total_amount = rgar($entry, '2'); // Replace '2' with the field ID of the total amount.

    if ($total_amount > 100) {
        $paypalEmail = '[email protected]';
    } else {
        $paypalEmail = '[email protected]';
    }

    return $paypalEmail;
}