Using Gravity Forms ‘gform_ppcp_object’ PHP filter

The gform_ppcp_object Gravity Forms PHP filter allows you to customize the GFPPCP object included in the form initialization scripts for the PayPal Field, available with the PayPal Commerce Platform Add-On.

Usage

A generic example of how to use the filter:

add_filter('gform_ppcp_object', 'your_function_name', 10, 2);

Parameters

  • $args (array): An array of arguments controlling the appearance and behavior of the PayPal Checkout and Credit Card field.
  • $form_id (int): The ID of the form containing the PayPal Field being prepared for display.

More information

See Gravity Forms Docs: gform_ppcp_object

Examples

Change PayPal Smart Payment Buttons Shape

This example demonstrates how to change the shape of the PayPal Smart Payment Buttons.

add_filter('gform_ppcp_object', 'ppcp_object_buttons_shape', 10, 2);

function ppcp_object_buttons_shape($args, $form_id) {
    $args['smartPaymentButtons']['buttonsShape'] = 'pill';
    return $args;
}

Change PayPal Smart Payment Buttons Layout

This example demonstrates how to change the layout of the PayPal Smart Payment Buttons.

add_filter('gform_ppcp_object', 'ppcp_object_buttons_layout', 10, 2);

function ppcp_object_buttons_layout($args, $form_id) {
    $args['smartPaymentButtons']['buttonsLayout'] = 'horizontal';
    return $args;
}

Change PayPal Smart Payment Buttons Size

This example demonstrates how to change the size of the PayPal Smart Payment Buttons.

add_filter('gform_ppcp_object', 'ppcp_object_buttons_size', 10, 2);

function ppcp_object_buttons_size($args, $form_id) {
    $args['smartPaymentButtons']['buttonsSize'] = 'small';
    return $args;
}

Change PayPal Smart Payment Buttons Color

This example demonstrates how to change the color of the PayPal Smart Payment Buttons.

add_filter('gform_ppcp_object', 'ppcp_object_buttons_color', 10, 2);

function ppcp_object_buttons_color($args, $form_id) {
    $args['smartPaymentButtons']['buttonsColor'] = 'blue';
    return $args;
}

Apply Customizations to Specific Form

This example demonstrates how to apply customizations only to a specific form with a given form ID.

add_filter('gform_ppcp_object', 'ppcp_object_specific_form', 10, 2);

function ppcp_object_specific_form($args, $form_id) {
    if ($form_id == 5) {
        $args['smartPaymentButtons']['buttonsColor'] = 'blue';
        $args['smartPaymentButtons']['buttonsShape'] = 'pill';
    }
    return $args;
}