Forcing people to choose a fund to give to.
-
Hello,
Please check out the donation page I have made for my church.
https://www.kingofkingsfellowship.com/donate/
I love Seamless Donation. We are receiving donations just fine. I have one question though. Is there anyway to force people to pick a specific fund to give to before proceeding to payment? As you can read off the webpage, I tell people “All none specified donations will be added to the General Tithe fund. To Give to another fund, please click the box for designated funds and select one from the list.”
But I would prefer to force people to choose. I have tried everything I can think of. Any help?
-
Nope. I have one user who has tried a ton of JavaScript and jQuery to hack it, but it’s not pretty (and probably not all that reliable). What you’re asking for is a common request, and may be something that finds its way into an add-on in the future.
Right now, though, I’m not focusing on adding new add-ons. Instead, I’m working on 4.0.15, which is a reliability and bug fix release to the core system.
–David
P.S. Marking as resolved because feature idea.
Thanks for the response. I do think this add on feature would be a great asset to the plug in. So much so that I’d being willing to search for other donation plug ins that meet that need.
Chris
Give is pretty popular. You might want to give it a try. I know it has add-ons, but I don’t know much about its overall feature set.
–David
I think I may be the user that David was referring to. I am no longer using JavaScript to set default funds – I have moved the logic to seamless-donations-form.php. It’s a more robust technique, I just need to be careful when updating the plugin, otherwise my customizations are lost. For example, I have two types of donation pages…
and
https://www.r4wh.org/team-r4wh/2016-riders/ian-downs/
With the /donate page, the checkbox that reveals the fund dropdown is pre-selected and hidden – it’s obvious to the user to look for a specific fund. The user is not forced to choose a fund, but encouraged with greater visibility.
With the /team-r4wh/2016-riders/ian-downs page, the fund is pre-selected for the user and cannot be modified – the fields are hidden but submitted with the form. In this example, the “Ian Down’s Ride” fund is pre-selected – this seems reasonable as the user is donating form Ian Down’s page.
I would imagine you’re looking for this type of functionality and if you feel comfortable playing around with the PHP, it’s not that difficult. Here’s a bit of my custom code that should illustrate the important part.
// Designated Funds if( get_option ( 'dgx_donate_show_designated_funds_section' ) == 'true' ) { // in 4.0+ funds are a custom post type, not an option array $query_args = array( 'orderby' => 'title', 'order' => 'asc', 'post_type' => 'funds', 'post_status' => 'publish', 'numberposts' => -1, 'meta_query' => array( array( 'key' => '_dgx_donate_fund_show', 'value' => 'Yes', ) ) ); $posts_array = get_posts ( $query_args ); $fund_count = count ( $posts_array ); if( $fund_count > 0 ) { $options_array = array( 0 => 'No rider specified', ); foreach( $posts_array as $post ) { $title = $post->post_title; $id = $post->ID; $options_array[ $id ] = $title; } // Hack by Ariel Kanevsky in order to pre-select riders on rider pages $url_fields = array_filter(explode('/', $_SERVER['REQUEST_URI'])); if (!ctype_alpha(substr(end($url_fields), 0, 1))) { // URL likely ends in some arguments, chop them off array_pop($url_fields); } $rider = str_replace('-', ' ', end($url_fields)); // Rider funds should be named following a "John Doe's Ride" convention if ($matched_rider = preg_grep("/^$rider/i", $options_array)) { // We're at a rider's page, set input values accordingly $funds_section = array( 'elements' => array( '_dgx_donate_designated_fund' => array( 'type' => 'hidden', 'value' => esc_attr(key($matched_rider)) ), ), ); } elseif (($rider == 'donate') || ($rider == 'alumni')) { // We're at the general donation page, set input values accordingly $donation_section['elements']['_dgx_donate_designated'] = array( 'type' => 'checkbox', 'id' => 'dgx-donate-designated', 'select' => true, 'prompt' => esc_html__ ("I would like to designate this donation to a specific fund", 'seamless-donations'), 'style' => 'display:none' ); $funds_section = array( 'elements' => array( 'designated_fund_label' => array( 'type' => 'static', 'value' => esc_html__ ( 'I would like my donation to be credited towards the following rider\'s fundraising goal:', 'seamless-donations' ) . " ", ), '_dgx_donate_designated_fund' => array( 'type' => 'select', 'class' => '', 'options' => $options_array, ), ) ); if ($rider == 'alumni') { // We're at the alumni donation page, set monthly donations and change the values $repeating_section = array( 'elements' => array( '_dgx_donate_repeating' => array( 'type' => 'hidden', 'value' => true, 'id' => 'dgx-donate-repeating', ) ) ); $donation_section['repeating_section'] = $repeating_section; // assemble the radio buttons for the giving levels $giving_levels = dgx_donate_get_giving_levels(); foreach ($giving_levels as $giving_level) { unset($donation_section['elements']["dgx_donate_giving_level_$giving_level"]); } unset($giving_level_key, $giving_level_option, $formatted_amount, $element); unset($donation_section['elements']['other_radio_button']); unset($donation_section['elements']['_dgx_donate_user_amount']); $giving_levels = array( 'supporter' => 5, 'intern' => 10, 'resident' => 25, 'attending' => 50, 'chair' => 100 ); $per_month_suffix = ' per month <br />'; foreach ($giving_levels as $training_level => $giving_level) { $giving_level_key = "dgx_donate_giving_level_" . $giving_level; $per_month_prefix = ucfirst(str_replace('_', ' ', $training_level)) . ' - '; if ($training_level == 'chief') { $per_month_suffix = $per_month_suffix . '<br />'; } $formatted_amount = $per_month_prefix . seamless_donations_get_escaped_formatted_amount($giving_level, 0) . $per_month_suffix; $element = array( 'type' => 'radio', 'group' => '_dgx_donate_amount', 'wrapper' => 'span', 'value' => $giving_level, 'prompt' => $formatted_amount, ); $donation_section['elements'][$giving_level_key] = $element; } } } $donation_section['funds_section'] = $funds_section; } }
Thanks, Ariel. You were indeed the person I was thinking about. Just be careful, because automatic plugin updates will overwrite this file, and as one of the main files, it’s changed rather often.
–David
P.S. Ariel, would you like a hook for your code? Help me figure out how to generalize the action call, and I can put a hook in there. That way, you can move your code to a plugin and not get it hammered on each release.
Thanks! I definitely like the /donate page. I think most people will see the option and make a selection. However, since I am volunteering and making this for my church and am self taught on WordPress, I do not feel comfortable messing with the .php. I have literally never used word press before creating this site. I more or less just know how to google things when I’m stuck. Is that code specific to your website? Or could I copy and paste it into mine? I’m assuming not. Thanks for all your help. David if this could be built into an update that would be so awesome! Thanks for your help!
David – I could give it a shot. I know this is a heavily requested feature. My time, like everyone else’s, is limited.
Chris – that is NOT generalized code. It works in my specific instance however draws on techniques that should be transferable. If you’re just hoping to alter the one form on the single URL, I could do it for you if you grant me access, however, as David mentioned, updating the plugin will erase the customization.
Ariel,
Thanks so much for the offer, but I will wait to see if it’s included in an update or look for another donation plug in. Just not comfortable giving access, which I’m sure you can appreciate. This feature would be a nice, but it is not necessary. Again, thanks so much to you and David for the help and insight! I really do appreciate it!
I would also like to have the ability to force a fund selection. For automatically hiding the fund display checkbox and revealing the fund list, I found that redefining the ‘cloak’ to ‘ ‘ (nothing) didn’t work. Apparently any definition of ‘cloak’, even a blank value, will hide a field. So the entire array for that field has to be passed through the filter without a ‘cloak’ value. Then, because that array fills the ‘options’ field with the variable $options_array, you have to include the query above that defines $options_array, but without the if statement at the beginning that looks to see if the funds section should be displayed, and without the bit that displays the checkbox field.
This was actually handy for me because I wanted to change the fund orderby to menu_order, and change the ‘No fund specified’ text. However, if this could all be done in the future without copying so much of the original code, it would be nicer.
My final code looked like this:
/* Reveal Fund Options Select Field *************************************/ // remove cloak from label (cloak/reveal overides select) add_filter( 'seamless_donations_form_donation_section', 'es_remove_funds_label_cloak' ); function es_remove_funds_label_cloak( $array ) { $array['elements']['designated_fund_label'] = array( 'type' => 'static', //'cloak' => 'specific-fund', 'value' => esc_html__ ( 'Designated Project: ', 'seamless-donations' ) . " ", ); return $array; } // remove cloak from select field (cloak/reveal overides select) // change orderby to menu_order and use 'project' instead of 'fund' in default option add_filter( 'seamless_donations_form_donation_section', 'es_remove_funds_field_cloak' ); function es_remove_funds_field_cloak( $array ) { $query_args = array( 'orderby' => 'menu_order', 'order' => 'asc', 'post_type' => 'funds', 'post_status' => 'publish', 'numberposts' => - 1, 'meta_query' => array( array( 'key' => '_dgx_donate_fund_show', 'value' => 'Yes', ) ) ); $posts_array = get_posts ( $query_args ); $fund_count = count ( $posts_array ); if ( $fund_count > 0 ) { $options_array = array( 0 => 'No project specified', ); foreach( $posts_array as $post ) { $title = $post->post_title; $id = $post->ID; $options_array[ $id ] = $title; } } $array['elements']['_dgx_donate_designated_fund'] = array( 'type' => 'select', //'cloak' => 'specific-fund', 'class' => '', 'options' => $options_array, ); return $array; } /* Check and Hide Fund Selection Display Field ***********************************************/ // remove reveal from display checkbox, check by default, change to hidden field, and remove prompt add_filter( 'seamless_donations_form_donation_section', 'es_remove_funds_reveal' ); function es_remove_funds_reveal( $array ) { $array['elements']['_dgx_donate_designated'] = array( 'type' => 'hidden', 'select' => '1', 'id' => 'dgx-donate-designated', //'reveal' => 'specific-fund', //'prompt' => esc_html__ ("I would like to designate this donation to a specific fund", 'seamless-donations' ), ); return $array; }
Very cool. For information on cloak and other array definitions, take a look at the forms engine in the Seamless Donations Codex at https://zatzlabs.com/project/seamless-donations-codex/.
Hmm. Actually, not cool. It doesn’t work. For some reason redefining the _dgx_donate_designated_fund array creates an additional dropdown list of funds that aren’t saved when a donation is completed. The original list still exists, but can no longer be seen because the _dgx_donate_designated is hidden, so all donations come in as “No fund specified”.
Should this solution work, but I’m just missing something? I’m back to altering core plugin files…
Hi
Thanks for the code “esaner”
I took what you published and with a bit of trial and error got it to work. I combined the 3 functions that you presented.
I also took the logic that Ariel presented( not shown in my code) and adapted that so that a customized donation page exists for each participant by using a registration process. Makes it so much easier for people to donate to the correct fund. Hope it might help someone because both snippets certainly helped meadd_filter( 'seamless_donations_form_donation_section', 'es_remove_funds_field_cloak' ); function es_remove_funds_field_cloak( $array ) { // data for dropdown $query_args = array( 'orderby' => 'menu_order', 'order' => 'asc', 'post_type' => 'funds', 'post_status' => 'publish', 'numberposts' => - 1, 'meta_query' => array( array( 'key' => '_dgx_donate_fund_show', 'value' => 'Yes', ) ) ); $posts_array = get_posts ( $query_args ); $fund_count = count ( $posts_array ); if ( $fund_count > 0 ) { $options_array = array( 606 => 'No Rider', ); foreach( $posts_array as $post ) { $title = $post->post_title; $id = $post->ID; $options_array[ $id ] = $title; } } // remove the check box $array['elements']['_dgx_donate_designated'] = array( 'type' => 'checkbox', 'select' => '1', 'id' => 'dgx-donate-designated', 'cloak' => 'specific-fund', //'prompt' => esc_html__ ("I would like to designate this donation to a specific fund", 'seamless-donations' ), ); $array['funds_section'] = array( 'elements' => array( 'designated_fund_label' => array( 'type' => 'static', //'cloak' => 'specific-fund', 'reveal' => 'specific-fund', 'value' => esc_html__ ( 'Select your Rider: ', 'seamless-donations' ) . " ", ), '_dgx_donate_designated_fund' => array( 'type' => 'select', //'cloak' => 'specific-fund', 'reveal' => 'specific-fund', 'class' => '', 'options' => $options_array, ), ), ); //echo " <pre>"; print_r( $array ); echo "</pre> "; return $array; }
Make sure to put that in a plugin and initiate it from one of the form hooks. That way, you won’t get clobbered with the next code update.
–David
Thanks David
I should have mentioned it is im my “custom seamless” plugin
MichaelPerfect!
- The topic ‘Forcing people to choose a fund to give to.’ is closed to new replies.