Charitable Blog

Everything you need to know about Charitable and our team.

AWARE: 30 for 30 campaign banner

An Inside Look at AWARE Whistler’s Unique “30 for 30” Fundraiser (Tutorial)

Last updated on

  • By

AWARE Whistler is a charity committed to protecting the natural environment of Whistler, Canada. It marks its 30th anniversary as an organisation this year and is celebrating the occasion by launching the 30 for 30 Fundraiser.

The goal of the 30 for 30 Fundraiser is to raise $60,000, with $30,000 raised from businesses and $30,000 raised from individual donations.

AWARE are using Charitable’s campaign-driven fundraising approach to power this campaign, with two individual fundraising campaigns set up: one for businesses, and one for individuals.

The challenge

Of course, unique campaigns like this tend to have unique needs, and the 30 for 30 Fundraiser is no exception.

Since one of the two fundraising campaigns is specifically focused on getting donations from businesses, a Company Name field is needed in that campaign’s donation form. Also, when donors are shown on the site (using the Donors shortcode or widget), it’s the company’s name that should be shown — not the name of the person donating.

Thankfully, Charitable’s flexibility is ideally suited for AWARE’s needs. Let’s see how.

Step 1. Add a “Company Name” field

The first thing we need to do is to create a new donation field, using the Donation Fields API.

Let’s look at the code required to achieve that:

/**
 * STEP 1: Register the "Company Name" Donation Field.
 *
 * On the `init` hook, we create a new Donation Field. It has a
 * key of `company_name` (this is how we will reference it later),
 * and it's set up as a required field in the donation form, shown
 * after the `last_name` field.
 */
add_action( 'init', function() {
        /**
         * Add a "Company Name" field.
         */
        $field = new Charitable_Donation_Field(
            'company_name',
            [
                'label' => 'Company Name',
                'data_type' => 'user',
                'donation_form' => [
                    'show_after' => 'last_name',
                    'required' => true,
                ],
                'admin_form' => true,
                'show_in_meta' => true,
                'show_in_export' => true,
                'email_tag' => [
                    'description' => 'The company name',
                ],
            ]
        );

        /**
         * Register the field.
         */
        charitable()->donation_fields()->register_field( $field );
}, 100 );

There’s a bit going on here. First of all, right at the top, we are setting up a function to be run on the init hook. This is the best hook to use any time you want to register a new donation field.

Inside of our function, we create a new Donation Field with the Charitable_Donation_Field object. Let’s take a closer look at that bit:

$field = new Charitable_Donation_Field(
     'company_name',
     [
         'label' => 'Company Name',
         'data_type' => 'user',
         'donation_form' => [
             'show_after' => 'last_name',
             'required' => true,
         ],
         'admin_form' => true,
         'show_in_meta' => true,
         'show_in_export' => true,
         'email_tag' => [
             'description' => 'The company name',
         ],
     ]
 );

What we’re doing here is creating a field with a key of company_name (we’ll need this later on). We have set a label, defined it as a user field, and set up some basic rules for how it should appear in the donation form: right after the last_name field and as a required field.

We’ve also set it up to show in the admin donation form, the donation meta and donations export file. We even told Charitable to create an email tag for it, so we can use it in our donation receipt emails.

Finally, we register this field with the Donation Fields API:

charitable()->donation_fields()->register_field( $field );

Step 2. Only show the “Company Name” field on one campaign

By default, when you set up a donation field, it will show up in every campaign’s donation form. For the “30 for 30” campaign though, AWARE only want the field to appear in the donation form of the Business fundraiser.

Here’s how we achieve that:

/**
 * STEP 2: Only show the field on a specific campaign.
 *
 * We only want the field to show up on a single campaign's
 * form, so we *remove* it from all other campaigns' donation
 * forms.
 */
add_filter( 'charitable_donation_form_user_fields', function( $fields, Charitable_Donation_Form $form ) {
    /**
     * Check the campaign ID of the donation form being
     * shown. If it isn't the one where we want the field,
     * remove the field using the unset() function.
     */
    if ( 123 != $form->get_campaign()->ID ) {
        unset( $fields['company_name'] );
    }

    return $fields;
}, 10, 2 );

The way we solve this problem is by removing the company_name field when we are not showing the Business campaign’s donation form. All the magic happens rights here:

if ( 123 != $form->get_campaign()->ID ) {
     unset( $fields['company_name'] );
 }

In this case, we’re imaging that the Business campaign has an ID of 123. So when we’re looking at the fields in a particular form, we check the ID of the campaign for the form, and if it isn’t 123, we use the unset() function to get rid of our field, referencing to it by the key of company_name, which we set in Step 1.

Step 3. Customise the donor name in the Donors shortcode or widget

Now that we’ve added our Company Name field, all that’s left is for us to use that instead of the donor’s first and last name when showing donations to the Businesses campaign.

Let’s see the code:

/**
 * STEP 3: Use the company name for the donor name.
 *
 * When showing the donor name for a particular donation,
 * check if the donation was to the campaign with our
 * Company Name field. If it was, show the Company Name
 * instead of the individual's name.
 */
add_filter( 'charitable_donor_loop_donor_name', function( $name, $args ) {
    /**
     * Get the Donor object from the argument array.
     */
    $donor = $args['donor'];

    /**
     * Check if there is a Donation object associated
     * with this Donor.
     */
    $donation = $donor->get_donation();

    if ( ! $donation ) {
        return $name;
    }

    /**
     * Get the campaign that received the donation.
     */
    $campaign_id = current( $donation->get_campaign_donations() )->campaign_id;

    /**
     * If this was a donation to our campaign,
     * let's change the donor name.
     */
    if ( 123 == $campaign_id ) {
        $name = $donation->get( 'company_name' );
    }

    return $name;
}, 15, 2 );

First of all, notice that this is set up as a function called on the charitable_donor_loop_donor_name hook. We use this hook since it is shown whenever a list of donors is shown with the Donors widget or shortcode.

Inside the function, we first get the Charitable_Donor object from the $args parameter. We then get the Charitable_Donation object through the $donor->get_donation() method:

/**
 * Check if there is a Donation object associated
 * with this Donor.
 */
$donation = $donor->get_donation();

if ( ! $donation ) {
    return $name;
}

You may wonder why we check whether $donation is set. The reason for this is because sometimes, Charitable_Donor is not set up with a specific donation. One such example is when the Donors widget/shortcode is set up to group multiple donations by the same donor into one — in that case, no Charitable_Donation object is called up, and we will just show the donor’s name.

Therefore, an important caveat of this approach is that this will only work if the Donors widget/shortcode is set up to show each donation individually, instead of grouping multiple donations by the same person.

Moving on, we use the Charitable_Donation object to find out which campaign was donated to, and check if it’s our Business campaign (the one with an ID of 123):

/**
 * Get the campaign that received the donation.
 */
$campaign_id = current( $donation->get_campaign_donations() )->campaign_id;

/**
 * If this was a donation to our campaign,
 * let's change the donor name.
 */
if ( 123 == $campaign_id ) {
    $name = $donation->get( 'company_name' );
}

The last part of this simply checks that the $campaign_id is 123. If it is, we get the company name like this:

$donation->get( 'company_name' );

Note that company_name matches the key of the donation field we registered back in step 1.

And with that, we’re all done!

The complete solution

You can see all the code put together in one place in our Github code library:

https://github.com/Charitable/library/blob/master/tutorials/new-donation-field-plus-customized-donor-name.php

To see it in action – and if you would like to show your support for the important work done by AWARE Whistler – visit the 30 for 30 Fundraiser page on their website.

Final word

If you enjoyed this tutorial and would like to see us write one about a different topic, let us know! You can reach us via email by filling out the form over at our Support page, or leave a comment below.

author avatar
Eric Daams

Disclosure: Our content is reader-supported. This means if you click on some of our links, then we may earn a commission. We only recommend products that we believe will add value to our readers.

Leave a Reply

Your email address will not be published. Required fields are marked *

Get free tips and resources right in your inbox, along with 60,000+ others

Join our Newsletter

We won’t spam you. We only send an email when we think it will genuinely help you. Unsubscribe at any time!

Featured Video:

Watch more videos on our YouTube channel.

What's New In Charitable

🔔 Subscribe to get our latest updates
📧 Subscribe to Emails

Email Subscription

Join our Newsletter

We won’t spam you. We only send an email when we think it will genuinely help you. Unsubscribe at any time!

donation form New

👉🏻 New Campaign Selector For Donation Forms

Take your campaign management to the next level. Find the perfect fundraiser for any page and stay in your creative flow with our new Campaign Selector integration.

The Ultimate Selection Tool

No more hunting for IDs or creating one page for every donation form. Use the new Campaign Selector to allow users to switch to a campaign with no code.

⚡ Instant Search: Quickly find any campaign leaving your page or post.

⚙️ Editor Agnostic: Whether you’re using the Block Editor, Elementor, or WPBakery, selecting your campaigns is now a unified experience.

🚀 Real-Time Previews: See exactly which campaign you’ve selected instantly, ensuring your donors always see the right cause.

author avatar
Eric Daams
Integration New

WordPress Command Palette Integration

Take your fundraising workflow to the next level. Speed up your site management and stay in your creative flow with our new WordPress Command Palette integration.

Supercharge Your Workflow
Navigate your fundraising dashboard faster than ever.

The Ultimate Keyboard Shortcut Hit Cmd + K (or Ctrl + K) to launch the Command Palette and manage your campaigns instantly.

⚡ Instant Navigation: Jump directly to your Campaigns, Donations, or Settings from anywhere in the editor.

➕ Quick Create: Start a new fundraising campaign or add a manual donation with a single command.

Efficiency Redefined
The tools you need, exactly when you need them.

⚙️ Contextual Actions: See relevant Charitable commands based on whether you’re editing a page or viewing your reports.

🚀 Seamless Integration: Built directly into the WordPress core experience for a lightweight, native feel.

author avatar
Eric Daams
Improvement New Security

📣 New Security Features

We’ve introduced a suite of new security tools to give you total control over who accesses your forms, plus a new way to tidy up your database.

Advanced Security Suite

Layered protection: Cloudflare, ReCAPTCHA, IP Controls, and Rate Limiting.

We have overhauled our security settings to stop bots without blocking real donors.

  • 🤖 Flexible Protection: Choose between Google reCAPTCHA v3 or the privacy-first Cloudflare Turnstile to block bots invisible.

  • 🚦 Rate limiting: Stop spam floods by limiting how many submissions an IP address can make in a set timeframe.

  • 🛑 Total control: Use the new IP Blacklist to block bad actors instantly, or the IP Whitelist to let your team bypass checks during testing.

The Clean Donation Tool

Go from “Testing” to “Live” in seconds.

Finished setting up your site and need to get rid of all those test transactions?

  • 🧹 Sweep it clean: Bulk delete test donations and donor records with a single click.

  • 📉 Accurate reporting: Ensure your revenue stats are 100% accurate for launch day.

  • ⚙️ Reset sequences: Automatically resets sequential invoice numbering.

author avatar
Eric Daams
donation form New

🏗️ Visual Donation Form Builder

Building the perfect donation form just got easier. We have completely reimagined how you create forms with a new drag-and-drop interface.

Design Visually, in Real-Time

No coding, no guessing. Just point, click, and build.

Say goodbye to confusing settings pages. You can now edit your form and see exactly what your donors will see, instantly.

  • 🖱️ Drag & Drop: Easily add fields like names, addresses, or file uploads by dragging them exactly where you want them.

  • 🎨 Customize everything: Click any field to tweak labels, placeholders, and requirement settings on the fly.

  • 👁️ Live preview: See your changes immediately as you make them—ensure your form flows perfectly before you hit publish.

Flexible & Powerful

Works with all your existing campaigns.

  • 🧩 Deep customization: Add custom HTML, shortcodes, or CSS classes for advanced branding.

  • ⚙️ Smart fields: Collect exactly what you need with support for dropdowns, checkboxes, dates, and hidden fields.

author avatar
Eric Daams
Leaderboards New

🏆 Donor Leaderboards!

Turn your fundraising into a community event. Recognize your most generous supporters and inspire friendly competition with our new leaderboard tools.

Gamify Your Fundraising

Celebrate your top donors and encourage others to climb the ranks.

Create a public “Hall of Fame” to give your donors the recognition they deserve.

  • 🎨 Two stunning layouts: Choose the List View for a clean, data-rich table or the Card View for a modern, visual grid with avatars.

  • 🥇 Automatic highlights: The top 3 supporters get special Trophy and Crown icons to make them stand out.

  • 🧩 Place it anywhere: Add it to any page using the new Gutenberg Block, or drop it directly into your campaign using the Visual Builder.

Total Customization

You decide what to show and what to hide.

  • ⚙️ Flexible data: Choose to display or hide donation amounts, donor counts, or avatars.

  • 🔄 Lifetime stats: Works seamlessly with Recurring Donations to show a donor’s all-time total impact.

author avatar
Eric Daams