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

suredonation_registered_payment_methods Filter Hook

Overview

The suredonation_registered_payment_methods filter allows developers to modify the payment methods registered for a SureDonation payment block.

It acts as the gateway-independent source for determining which payment methods are available for rendering in the payment methods accordion on the frontend.

You can use this filter to:

  • Add a custom payment method.
  • Modify an existing payment method.
  • Change the payment method label.
  • Enable or disable a payment method.
  • Customize the frontend container class or ID.
  • Add custom payment method configuration.

When to Use This Filter

Use this filter when you need to register a custom payment method or modify the frontend configuration of an existing payment method.

For example, a custom gateway can use this filter to register its payment method so SureDonation can include it in the payment methods accordion.

Filter Signature

apply_filters( 'suredonation_registered_payment_methods', $methods, $this->payment_methods, $this->block_id);

Parameters

ParameterTypeDescription
$methodsarrayRegistered payment methods keyed by method ID.
$payment_methodsarrayPayment methods selected in the current payment block.
$block_idstringID of the payment block.

$methods

Each registered payment method can contain configuration values such as:

KeyDescription
idUnique ID of the payment method.
labelDisplay label shown to the donor.
enabledDetermines whether the payment method is enabled.
container_classCSS class used for the payment method container.
container_idContainer ID used by payment methods such as Stripe.
contentHTML content displayed for payment methods such as Offline payments.

The exact configuration can vary depending on the payment method.

Return Value

Return an array containing the registered payment method configurations.

The array should be keyed by the payment method ID.

$methods['mygateway'] = [  

// Payment method configuration.

];

Basic Usage

Use add_filter() to register your callback.

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

function your_custom_function( $methods, $payment_methods, $block_id ) {

    // Add or modify registered methods here.

    return $methods;

}

Example: Register a Custom Payment Method

The following example registers a custom payment method named mygateway when it has been selected in the payment block.

add_filter( 'suredonation_registered_payment_methods', 'mysite_register_method', 10, 3);

function mysite_register_method( $methods, $payment_methods, $block_id ) {

    if ( in_array( 'mygateway', $payment_methods, true ) ) {

        $methods['mygateway'] = [

            'id'              => 'mygateway',

            'label'           => __( 'My Gateway', 'my-plugin' ),

            'enabled'         => true,

            'container_class' => 'sd-mygateway',

            'container_id'    => 'sd-mygateway-' . $block_id,

        ];

    }

    return $methods;

}

How the Example Works

  1. The callback checks whether mygateway is selected in the payment block.
  2. If selected, the custom payment method is added to $methods.
  3. A label is defined for the payment method.
  4. The method is enabled.
  5. A CSS class and unique container ID are assigned.
  6. The modified $methods array is returned.

Example: Modify an Existing Payment Method

You can also modify the configuration of an existing payment method.

add_filter( 'suredonation_registered_payment_methods',  'mysite_modify_payment_label',  10,  3);

function mysite_modify_payment_label( $methods, $payment_methods, $block_id ) {

    if ( isset( $methods['stripe'] ) ) {

        $methods['stripe']['label'] = __( 'Pay by Card', 'my-plugin' );

    }

    return $methods;

}

This changes the frontend label of the Stripe payment method to Pay by Card.

Payment Method Rendering

The registered payment methods returned by this filter are used by SureDonation to generate the frontend payment methods accordion.

The general flow is:

  1. A payment block is loaded.
  2. SureDonation determines the payment methods selected in the block.
  3. Registered payment method configurations are prepared.
  4. The suredonation_registered_payment_methods filter is applied.
  5. Custom code can add or modify payment methods.
  6. SureDonation uses the returned configuration to render the payment methods accordion.

  • Payment_Markup::get_registered_payment_methods()

The result of this filter directly affects the payment methods rendered in the frontend payment accordion.

When registering a custom method, ensure that its method ID is unique and that the required frontend configuration is provided.

Related Hooks

  • suredonation_available_payment_methods: Controls the available payment methods that can be selected for a payment block.
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