Braintree for WooCommerce: Action and Filter Hooks

Use this reference to customize PayPal Enterprise Payments (formerly Braintree) with actions and filters. Translation text domains are listed at the end of the page.

Note:

This is a Developer level doc. If you are unfamiliar working with code and resolving potential conflicts, we recommend you work with a Woo Agency Partner for larger projects, or find a WooCommerce developer on Codeable for smaller customizations. We are unable to provide support for customizations under our Support Policy.

Actions

↑ Back to top

Customizations are not covered under our support policy, so this isn’t something we can help implement or troubleshoot on your site.

Note:

This is not an exhaustive list of all actions, but should cover most merchant use cases.

The [gateway_id] placeholders below can be ‘braintree_credit_card’ or ‘braintree_paypal’

wc_[gateway_id]_before_product_button_add_to_cart

↑ Back to top

Triggered directly before the add to cart button (where PayPal “Buy Now” buttons are added).

 do_action( 'wc_[gateway_id]_before_product_button_add_to_cart', $product_id, $quantity, $variation_id, $cart_data );

wc_payment_gateway_[gateway_id]_payment_processed

↑ Back to top

Fires when a payment is processed for an order.

/**
 * Payment Gateway Payment Processed Action.
 *
 * Fires when a payment is processed for an order.
 *
 * @since 4.1.0
 * @param \WC_Order $order order object
 * @param SV_WC_Payment_Gateway_Direct $instance instance
 */
 do_action( 'wc_payment_gateway_[gateway_id]_payment_processed', $order, $instance );

wc_payment_gateway_[gateway_id]_payment_method_added

↑ Back to top

Fires after a new payment method is added by a customer.

/**
 * Fires after a new payment method is added by a customer.
 *
 * @since 5.0.0
 *
 * @param string $token_id new token ID
 * @param int $user_id user ID
 * @param SV_WC_Payment_Gateway_API_Response $response API response object
 */
 do_action( 'wc_payment_gateway_[gateway_id]_payment_method_added', $token_id, $user_id, $response );

wc_payment_gateway_[gateway_id]_payment_method_deleted

↑ Back to top

Fires after a new payment method is deleted by a customer.

/**
 * Fires after a new payment method is deleted by a customer.
 *
 * @param string $token_id ID of the deleted token
 * @param int $user_id user ID
 *
 * @since 5.0.0
 *
 */
 do_action( 'wc_payment_gateway_[gateway_id]_payment_method_deleted', $token_id, $user_id );

wc_payment_gateway_[gateway_id]_complete_payment

↑ Back to top

Fires after a payment transaction is successfully completed.

/**
 * Fires after a payment transaction is successfully completed.
 *
 * @since 5.0.0
 *
 * @param \WC_Order $order order object
 * @param SV_WC_Payment_Gateway $gateway gateway object
 */
 do_action( 'wc_payment_gateway_[gateway_id]_complete_payment', $order, $gateway );

wc_payment_gateway_[gateway_id]_refund_processed

↑ Back to top

Fires after a refund is successfully processed.

/**
 * Fires after a refund is successfully processed.
 *
 * @since 5.1.0
 *
 * @param \WC_Order $order order object
 * @param SV_WC_Payment_Gateway $gateway payment gateway instance
 */
 do_action( 'wc_payment_gateway_[gateway_id]_refund_processed', $order, $gateway );

Filters

↑ Back to top

Note:

This is not an exhaustive list of all filters, but should cover most merchant use cases.

The [gateway_id] placeholders below can be ‘braintree_credit_card’ or ‘braintree_paypal’

wc_braintree_api_request_data

↑ Back to top

Modify the request data before it’s sent to Braintree.

/**
 * Braintree API Request Data.
 *
 * Allow actors to modify the request data before it's sent to Braintree.
 *
 * @since 3.0.0
 *
 * @param array|mixed $data request data to be filtered
 * @param \WC_Braintree_API_Request $instance, API request class instance
 */
 apply_filters( 'wc_braintree_api_request_data', $data, $instance );

wc_braintree_transaction_data

↑ Back to top

Filter the request data for new transactions.

/**
 * Filters the request data for new transactions.
 *
 * @since 2.0.0
 * @param array $data The transaction/sale data
 * @param \WC_Braintree_API_Transaction_Request $request the request object
 */
 apply_filters( 'wc_braintree_transaction_data', $data, $request );

wc_[gateway_id]_button_styles

↑ Back to top

Filter the PayPal button style parameters.

/**
 * Filters the PayPal button style parameters.
 *
 * @see https://developer.paypal.com/docs/checkout/integration-features/customize-button
 *
 * @since 2.1.0
 *
 * @param array $styles style parameters
 */
 apply_filters( 'wc_[gateway_id]_button_styles', $styles );

wc_[gateway_id]_js_args

↑ Back to top

Filter the JavaScript handler arguments.

/**
 * Filters the JavaScript handler arguments.
 *
 * @since 5.7.0
 *
 * @param array $args arguments to pass to the JS handler
 * @param Script_Handler $handler script handler instance
 */
 apply_filters( 'wc_[gateway_id]_js_args', $args, $handler );

wc_[gateway_id]_default_tokenize_payment_method_checkbox_to_checked

↑ Back to top

Default the tokenize payment method checkbox state to checked.

/**
 * Allow actors to default the tokenize payment method checkbox state to checked.
 *
 * @since 4.2.0
 *
 * @param bool $checked default false, set to true to change the checkbox state to checked
 * @param SV_WC_Payment_Gateway_Payment_Form $instance payment form instance
 */
 apply_filters( 'wc_[gateway_id]_default_tokenize_payment_method_checkbox_to_checked', $checked, $instance );

wc_payment_gateway_[gateway_id]_form_fields

↑ Back to top

Add, remove, or tweak gateway form fields.

/**
 * Actors can use this to add, remove, or tweak gateway form fields
 *
 * @since 4.0.0
 * @param array $form_fields array of form fields in format required by WC_Settings_API
 * @param \SV_WC_Payment_Gateway $instance gateway instance
 */
 apply_filters( 'wc_payment_gateway_[gateway_id]_form_fields', $form_fields, $instance );

wc_braintree_paypal_disabled_funding_options

↑ Back to top

Filter the PayPal disabled funding options. See all options here.

/**
 * Filters the PayPal disabled funding options.
 *
 * @param array $disabled_funding_options list of current disabled funding options
 * @param \WC_Braintree_PayPal_Payment_Form $form payment form instance
 */
 apply_filters( 'wc_braintree_paypal_disabled_funding_options', $disabled_funding_options, $form );

sv_wc_external_checkout_terms_notice_text

↑ Back to top

Filter the text for the terms & conditions notice.

/**
 * Filter the text for the terms & conditions notice.
 *
 * @since 5.10.0
 *
 * @params string $default_text default notice text
 */
 apply_filters( 'sv_wc_external_checkout_terms_notice_text', $default_text );

wc_braintree_credit_card_payment_form_tokenization_forced

↑ Back to top

Force tokenization for Braintree credit card transactions when user is logged in – this hides the “securely save to account” checkbox.

add_filter( 'wc_braintree_credit_card_payment_form_tokenization_forced', '__return_true' );

wc_braintree_paypal_payment_form_tokenization_forced

↑ Back to top

Force tokenization for Braintree PayPal transactions when user is logged in, this hides the “securely save to account” checkbox.

add_filter( 'wc_braintree_paypal_payment_form_tokenization_forced', '__return_true' );

Translation text domains

↑ Back to top

The extension uses two text domains. Translate the extension’s own strings with woocommerce-gateway-paypal-powered-by-braintree and its shared framework strings with woocommerce-plugin-framework.

Follow Translating WooCommerce extensions for translation tools and file locations, including the guidance for the shared SkyVerge framework.

Use of your personal data
We and our partners process your personal data (such as browsing data, IP Addresses, cookie information, and other unique identifiers) based on your consent and/or our legitimate interest to optimize our website, marketing activities, and your user experience.