|
/ Documentation /Developer Hooks & Events/ suredonation_available_payment_methods Filter Hook

suredonation_available_payment_methods Filter Hook

The suredonation_available_payment_methods filter allows developers to modify the list of payment methods available on a SureDonation payment block.

SureDonation first checks which payment gateways are globally connected and enabled. This filter then allows extensions to add or remove payment method IDs from the final list.

Use this filter when your extension provides a custom payment gateway and you want to make it available in the payment block after the gateway has been connected.

Parameters

ParameterTypeDescription
$availablearrayPayment method IDs currently available after SureDonation’s connectivity checks. For example, stripe is available when Stripe is connected with a publishable key, while offline is available when offline donations are enabled.
$block_payment_methodsarrayPayment methods selected in the payment block. This comes from the paymentMethods block attribute and defaults to [‘stripe’].
$attributesarrayThe payment block’s attributes.

Return Value

Return an array containing the available payment method IDs.

If an empty array is returned, SureDonation falls back to the payment methods selected in the block.

Filter Source

apply_filters( 'suredonation_available_payment_methods', $available, $block_payment_methods, $attributes );

Filter Usage

add_filter( 'suredonation_available_payment_methods', 'your_custom_function', 10, 3 );

function your_custom_function( $available, $block_payment_methods, $attributes ) {

    // Add or remove available payment method IDs here.

    return $available;

}

Filter Example

The following example adds a custom gateway when it is selected in the payment block and the gateway is connected:

add_filter( 'suredonation_available_payment_methods', 'mysite_add_gateway', 10, 3 );

function mysite_add_gateway( $available, $block_payment_methods, $attributes ) {

    // Expose a custom gateway when it was selected in the block and is connected.

    if ( in_array( 'mygateway', $block_payment_methods, true ) && mysite_gateway_connected() ) {

        $available[] = 'mygateway';

    }

    return $available;

}
  • This filter is applied in Payment_Markup::__construct() during payment block rendering.
  • The returned array determines the payment methods that become active for the block.
  • When adding a custom gateway, make sure the gateway is actually connected and configured before adding its method ID.
  • The payment method ID added through this filter should match the ID used by your custom payment gateway integration.

Related Hooks

  • suredonation_registered_payment_methods
  • suredonation_enqueue_form_frontend_scripts
Was this doc helpful?
What went wrong?

We don't respond to the article feedback, we use it to improve our support content.

Need help? Contact Support
Table of Contents
Scroll to Top