Forum Replies Created

Viewing 9 replies - 1 through 9 (of 9 total)
  • Thread Starter malachite96

    (@malachite96)

    Hi Eric,

    Sorry for delay – Here’s the code for 4 fields. I want them to appear in the order they are coded below:

    Text: Dedicate my Donation
    Checkbox: Send Ack to the person or org for dedication
    Text: Acknowledge my Donation Publicly
    Checkbox: No, do not acknowledge my donation publicly

    However, what happens is the two text fields are appearing first, and then the two checkboxes, out of order from each other. Here’s the code:

    /**
    * Collect the donor’s Dedication wishes in the donation form.
    *
    * @param array[] $fields
    * @param Charitable_Donation_Form $form
    * @return array[]
    */
    function ed_collect_dedication( $fields, Charitable_Donation_Form $form ) {
    $fields[ ‘donor_dedication’ ] = array(
    ‘label’ => __( ‘Please dedicate my donation to (in honor of, in memoriam, etc.):’, ‘your-namespace’ ),
    ‘type’ => ‘text’,
    ‘priority’ => 22,
    ‘value’ => $form->get_user_value( ‘donor_dedication’ ),
    ‘required’ => false,
    ‘data_type’ => ‘user’
    );
    return $fields;
    }
    add_filter( ‘charitable_donation_form_user_fields’, ‘ed_collect_dedication’, 10, 2 );
    /**
    * Display the Dedication Information in the admin donation details box.
    *
    * @param array[] $meta
    * @param Charitable_Donation $donation
    * @return array[]
    */
    function ed_show_donor_dedication_in_admin( $meta, $donation ) {
    $donor_data = $donation->get_donor_data();
    $meta[ ‘donor_dedication’ ] = array(
    ‘label’ => __( ‘Dedication’, ‘your-namespace’ ),
    ‘value’ => $donor_data[ ‘donor_dedication’ ]
    );
    return $meta;
    }
    add_filter( ‘charitable_donation_admin_meta’, ‘ed_show_donor_dedication_in_admin’, 10, 2 );

    /**
    * Add a checkbox on the donation form to ask the donor whether they would like to have their donation DEDICATION acknowledged. Opt-IN Checkbox.
    *
    * @return void
    */
    function ed_add_donation_dedication_ack_opt_in_checkbox() {
    $ticked = isset( $_POST[ ‘donation_dedication_ack_optin’ ] ) && $_POST[ ‘donation_dedication_ack_optout’ ];
    ?>

    <div id=”charitable_field_donation_dedication_ack_optin” class=”charitable-form-field charitable-form-field-checkbox”>
    <input type=”checkbox” name=”donation_dedication_ack_optin” value=”1″ <?php checked( $ticked ) ?> />
    <label for=”charitable_field_donation_dedication_ack_optin”><?php _e( ‘Please send an acknowledgement to the individual or organization to whom I am dedicating my donation (contact information included above).’, ‘your-namespace’ ) ?></label>
    </div>
    <?php
    }
    add_filter( ‘charitable_donation_form_donor_fields_after’, ‘ed_add_donation_dedication_ack_opt_in_checkbox’ );
    /**
    * Add donation_ack_optin to the list of meta fields to be saved.
    *
    * @param mixed[] $meta
    * @param int $donation_id
    * @param Charitable_Donation_Processor $processor
    * @return mixed[]
    */
    function ed_save_donation_dedication_ack_opt_in_meta_field( $meta, $donation_id, Charitable_Donation_Processor $processor ) {
    $meta[ ‘donation_dedication_ack_optin’ ] = $processor->get_donation_data_value( ‘donation_dedication_ack_optin’ );
    return $meta;
    }
    add_filter( ‘charitable_donation_meta’, ‘ed_save_donation_dedication_ack_opt_in_meta_field’, 10, 3 );
    /**
    * The value for donation_dedication_ack_optout should always be either 1 or 0.
    *
    * @return int
    */
    function ed_save_submitted_value_donation_dedication_ack_opt_in( $values ) {
    $values[ ‘donation_dedication_ack_optin’ ] = isset( $_POST[ ‘donation_dedication_ack_optin’ ] ) && $_POST[ ‘donation_dedication_ack_optin’ ] ? 1 : 0;
    return $values;
    }
    add_filter( ‘charitable_donation_values’, ‘ed_save_submitted_value_donation_dedication_ack_opt_in’ );

    /**
    * Collect the donor’s Public Acknowledgement wishes in the donation form.
    *
    * @param array[] $fields
    * @param Charitable_Donation_Form $form
    * @return array[]
    */
    function ed_collect_donor_ack_name( $fields, Charitable_Donation_Form $form ) {
    $fields[ ‘donor_ack_name’ ] = array(
    ‘label’ => __( ‘Yes, you may acknowledge my donation publicly. Use this name (or names) to acknowledge my donation: (fill-in only if different from name entered above)’, ‘your-namespace’ ),
    ‘type’ => ‘text’,
    ‘priority’ => 24,
    ‘value’ => $form->get_user_value( ‘donor_ack_name’ ),
    ‘required’ => false,
    ‘data_type’ => ‘user’
    );
    return $fields;
    }
    add_filter( ‘charitable_donation_form_user_fields’, ‘ed_collect_donor_ack_name’, 10, 2 );
    /**
    * Display the Dedication Information in the admin donation details box.
    *
    * @param array[] $meta
    * @param Charitable_Donation $donation
    * @return array[]
    */
    function ed_show_donor_ack_name_in_admin( $meta, $donation ) {
    $donor_data = $donation->get_donor_data();
    $meta[ ‘donor_ack_name’ ] = array(
    ‘label’ => __( ‘Donor Public Name’, ‘your-namespace’ ),
    ‘value’ => $donor_data[ ‘donor_ack_name’ ]
    );
    return $meta;
    }
    add_filter( ‘charitable_donation_admin_meta’, ‘ed_show_donor_ack_name_in_admin’, 10, 2 );

    /**
    * Add a checkbox on the donation form to ask the donor whether they would like to have the donation acknowledged publicly.
    *
    * @return void
    */
    function ed_add_donation_public_ack_opt_out_checkbox() {
    $ticked = isset( $_POST[ ‘donation_ack_optout’ ] ) && $_POST[ ‘donation_ack_optout’ ];
    ?>
    <div id=”charitable_field_donation_ack_optout” class=”charitable-form-field charitable-form-field-checkbox”>
    <input type=”checkbox” name=”donation_ack_optout” value=”1″ <?php checked( $ticked ) ?> />
    <label for=”charitable_field_donation_ack_optout”><?php _e( ‘No, please do not acknowledge my donation publicly.’, ‘your-namespace’ ) ?></label>
    </div>
    <?php
    }
    add_filter( ‘charitable_donation_form_donor_fields_after’, ‘ed_add_donation_public_ack_opt_out_checkbox’ );
    /**
    * Add donation_ack_optout to the list of meta fields to be saved.
    *
    * @param mixed[] $meta
    * @param int $donation_id
    * @param Charitable_Donation_Processor $processor
    * @return mixed[]
    */
    function ed_save_donation_public_ack_opt_out_meta_field( $meta, $donation_id, Charitable_Donation_Processor $processor ) {
    $meta[ ‘donation_ack_optout’ ] = $processor->get_donation_data_value( ‘donation_ack_optout’ );
    return $meta;
    }
    add_filter( ‘charitable_donation_meta’, ‘ed_save_donation_public_ack_opt_out_meta_field’, 10, 3 );
    /**
    * The value for donation_ack_optout should always be either 1 or 0.
    *
    * @return int
    */
    function ed_save_submitted_value_donation_public_ack_opt_out( $values ) {
    $values[ ‘donation_ack_optout’ ] = isset( $_POST[ ‘donation_ack_optout’ ] ) && $_POST[ ‘donation_ack_optout’ ] ? 1 : 0;
    return $values;
    }
    add_filter( ‘charitable_donation_values’, ‘ed_save_submitted_value_donation_public_ack_opt_out’ );

    Thread Starter malachite96

    (@malachite96)

    Hi Eric – yes, I tried this and it works if all the fields in question are text fields. But there isn’t anywhere to add the ‘priority’ setting in the code for adding a checkbox field. Can you help with that?

    What’s happening is that my text fields are lining up above my checkbox fields and I can’t re-order any checkbox fields above any of the text fields – nor can I reorder the checkbox fields themselves.

    Thank you!

    Thread Starter malachite96

    (@malachite96)

    I was browsing around in your GitHub area and found a code snippet for adding a donation receipt opt-out checkbox. I have used this to create the checkboxes I needed. Still testing to see if the output comes out correctly, but so far the boxes do show up on the donation form.

    I’m closing this thread as resolved.

    Thanks!

    Thread Starter malachite96

    (@malachite96)

    Hi Eric,

    Can you help with a code snippet that creates a checkbox?

    Thank you,

    Beth

    Thread Starter malachite96

    (@malachite96)

    Eric – can you send code that doesn’t take away the donate button?

    Thread Starter malachite96

    (@malachite96)

    Hi Eric,

    Thank you for all these answers. About the customer field snippet – it looks like I need to add each one as a full snippet, right?

    I see that this national ID snippet adds Text and a Text field – how do I add a checkbox? (sorry, I’m new to creating php code.)

    Also – do you have a probable timeline for the recurring donations and newsletter subscription extensions?

    Also – is there any bundle of extensions that also gets access to new extensions as they are released?

    Thank you!

    Thread Starter malachite96

    (@malachite96)

    Hi Eric,

    This code snippet also took away the Donate button. Oops!

    Thank you,

    Thread Starter malachite96

    (@malachite96)

    That would be great to use for campaigns that have no end-date or a category.

    I will test this code snippet out on our site today and update this thread.

    Will need guidance on adding the category or non-end date adjustments.

    Thank you!

    Thread Starter malachite96

    (@malachite96)

    Is there a way to remove from our campaigns, but reveal them for Ambassadors once we set that option up? Thanks!

    – Malachite

Viewing 9 replies - 1 through 9 (of 9 total)