Display Custom Text in Radio/Button Selection Options

The Donation Platform for WooCommerce plugin offers a convenient way to accept donations through your WooCommerce store. One of its versatile features is the ability to display custom text in radio/button selection options. This allows you to provide more context or information to users when they select a donation amount.

This guide is intended for advanced users who possess a solid understanding of WordPress and PHP programming concepts. If you’re unfamiliar with these topics, it’s recommended to seek assistance or further resources to ensure successful implementation of the customization.

Filter Usage

You can achieve this customization using the wcdp_label_{$input_value} filter. This filter dynamically modifies the label displayed for a specific donation amount, where {$input_value} represents the amount set for the donation.

add_filter('wcdp_label_{$input_value}', function($label) {
    // Modify the label here
    return $modified_label;
});

Replace {$input_value} with the actual amount you want to customize, and within the callback function, modify the $modified_label variable to the desired text you wish to display.

Example

Let’s say you want to display ” $50 (10 Entries)” instead of just “$50” when users select the $50 donation option. You can achieve this using the following code:

add_filter('wcdp_label_50', function($label) {
    return '$50 (10 Entries)';
});

This code snippet hooks into the wcdp_label_50 filter and modifies the label to include the additional information about the number of entries users receive with a $50 donation.

You can use the following HTML: span, div (& theoretically input, but don’t use that) with the attributes class and id. For example:

add_filter('wcdp_label_50', function($label) {
    return '$50<div class="custom_wcdp_label">(10 Entries)</div>';
});

This will force a new line:

Tip

To easily add PHP code snippets like the ones provided above, consider using the free Code Snippets plugin. This type of plugin simplifies the process of adding and managing custom PHP code within your WordPress site, ensuring smooth integration of your customizations.

By utilizing the wcdp_label_{$input_value} filter, you can enhance the user experience by providing relevant information or context alongside donation options, thereby encouraging more contributions to your cause.