Home / Admin / Add Dropdown Field To Donation Form
Duplicate Snippet

Embed Snippet on Your Site

Add Dropdown Field To Donation Form

Shows how to add a custom dropdown in a donation form (this example the select field is called "Giving Type").

Code Preview
php
<?php
/**
 * Shows how to add a custom dropdown in a donation form (this example the select field is called "Giving Type")
 *
 * This snippet only works in Charitable 1.5 or above.
 *
 */
function wpchar_charitable_register_new_dropodown_field() {
    /**
     * Define a new text field.
     */
	
	if ( ! class_exists("Charitable_Donation_Field" ) ) {
		return;
	};
		
    /* Create the Donation Field instance. */
    $field = new Charitable_Donation_Field(
        'giving_type',
        array(
            'label'          => __( 'Giving Type' ), // what text shows up in the donation form.
            'data_type'      => 'meta', 
            'value_callback' => false,
            'donation_form'  => array(
                'type'       => 'select',  // the type of field to show in the donation form (text, checkbox, etc.)
				'options'    => array (
				'value-1' => 'label-1',
				'value-2' => 'label-2',
				'value=3' => 'label-3'),
                'required'   => false,   // whether the field is required.
                'show_after' => 'phone', // the field to show this one after.
            ), 
            'admin_form'     => true,
            'show_in_meta'   => true,
            'show_in_export' => true,
            'email_tag'      => array( // the tag to use in email notifications (make false to not add this to tags.
                'description' => __( 'The custom field value' ),
            ),
        )
    );
    /* Register it. */
    charitable()->donation_fields()->register_field( $field );
}
add_action( 'init', 'wpchar_charitable_register_new_dropodown_field' );

Comments

Add a Comment