Home / Admin / Add Multiple Checkboxes To Donation Form
Duplicate Snippet

Embed Snippet on Your Site

Add Multiple Checkboxes To Donation Form

This uses the "multi-checkbox" vs just "checkbox" for a single checkbox.

Code Preview
php
<?php
/**
 * Add a collection of checkboxes to the donation form.
 *
 * This snippet only works in Charitable 1.5 or above.
 *
 */
function wpchar_charitable_register_new_checkboxes_field() {
	
    if ( ! class_exists("Charitable_Donation_Field" ) ) {
	return;
    };
	
    /**
     * Define a new checkbox field.
     */
    $field = new Charitable_Donation_Field( 'new_checkboxes_field', array(
        'label' => __( 'New Checkboxes Field', 'charitable' ),
        'data_type' => 'user',
        'donation_form' => array(
            'type' => 'multi-checkbox',
            'show_before' => 'phone',
            'required'   => false,
            'options' => array (
                 'option_1_value' => 'Option One',
                 'option_2_value' => 'Option Two',
                 'option_3_value' => 'Option Three',
	     ),
        ),
        'admin_form' => true,
        'show_in_meta' => true,
        'show_in_export' => true,
        'email_tag' => array(
            'description' => __( 'The new checkbox field' , 'charitable' ),
        ),
    ) );
    /**
     * Register the checkbox field.
     */
    charitable()->donation_fields()->register_field( $field );
}
add_action( 'init', 'wpchar_charitable_register_new_checkboxes_field' );

Comments

Add a Comment