Charitable Documentation

Learn how to make the most of Charitable with clear, step-by-step instructions.

Customizing Donation Forms With Code Snippets Using WPCode

Often charitable campaign creators want to customize their donation forms. The most common customization is adding an additional field to the form, such as a text field to enter a specific code or an alternative email address. Other times, it is a checkbox to confirm if the donor would like to be informed of additional services.

It is possible to add custom fields to a donation form, and this can be done through easily modifiable code snippets that can be added to the functions.php file or a dedicated plugin. But for those who are not developers or are not comfortable with code, there is an easier and faster method to add and activate code snippets in Charitable using WPCode.

Installing WPCode

The first step is to install WPCode itself. You can install and activate the free version just like you can with any other WordPress plugin. However, Charitable has an easier built-in process.

Ensure that you are using the latest version of Charitable version 1.8.1.7 introduced a tools menu, and this is our first destination.

Go to “Tools” and then click on the “Code Snippets” tab. If you have not already installed WPCode, you should see a prompt that will allow you to install and activate the plugin right there.

Finding & Activating Code Snippets

Once that is successful, the same tab will be populated with code snippets. Each box on the page contains the title, a brief description, a link to the snippet’s location on WPCode, and an install button.

For example, if you were looking to add a custom text box to a donation form, search for “text box” in the search box and the page will update with results that match that keyword. You can locate an example script and click install, and that script will automatically be copied and added to your WPCode snippet library.

Customizing Code Snippets For Charitable

Often installed code snippets have comments and documentation inside them, so you can customize the snippet. For example, if I wanted a text area for a donor to share how they learned about the campaign, this “Add Textbox To Donation Formsnippet could be modified as shown here:

/**
 * Collect a textarea field in the donation form.
 *
 * This snippet only works in Charitable 1.5 or above.
 *
 */
function wpchar_charitable_register_new_textarea_field() {
    /**
     * Define a new textarea field.
     */
	
	if ( ! class_exists("Charitable_Donation_Field" ) ) {
		return;
	};
		
    $field_1 = new Charitable_Donation_Field( 'textarea_example', array(
        'label' => __( 'How did you learn about this campaign?', 'charitable' ),
        'data_type' => 'user',
        'donation_form' => array(
            'type' => 'textarea',
			'show_after' => 'phone', // adjust to where you want this to show up
                        'required'   => false,
             ),
        'admin_form' => false,
        'show_in_meta' => false,
        'show_in_export' => false,
        'email_tag' => array(
            'description' => __( 'How did you learn...' , 'charitable' ),
        ),
    ) );

    /**
     * Register the textarea fields.
     */
	charitable()->donation_fields()->register_field( $field_1 );

}

add_action( 'init', 'wpchar_charitable_register_new_textarea_field' );

There are many other snippets that go beyond creating a text box on a donation form and extend into customizing your campaigns and donation forms even further. Feel free to explore the library either on WPCode‘s website or in the screen in the Charitable plugin.

Have an idea for a code snippet that doesn’t exist yet? Contact us and we’ll add it!

You may also be interested in WPCode documentation to learn more about how their plugin works and the additional features that you can assign to code snippets, including Charitable code snippets.

Feel free to reach out to our support team if you have any questions.

Still have questions? We’re here to help!

Last Modified: