Charitable Blog

Everything you need to know about Charitable and our team.

Tutorial: Set Custom Receipt Pages per Campaign

Last updated on

  • By

By default, your site will have a single donation receipt page, which donors will automatically be redirected to after they make their donation.

You can use the auto-generated receipt page provided by Charitable out of the box, or you can specify a particular page to be used as your donation receipt page. Check the guide below if you’re not sure how to do this:

But what if you want to use a different receipt page for different campaigns? That isn’t possible out of the box, but thanks to Charitable’s built-in flexibility, it’s possible to achieve this with just two PHP functions.

The Solution

Our solution will add a new field to the campaign editor which allows you to select a static page as the donation receipt page for your campaign. Unless you choose a specific page, it will use the default option, which is whatever is set at Charitable > Settings > General for the “Donation Receipt Page” option.

I will explain the solution below, but if you just want the code, you can download it from Github:

https://github.com/Charitable/Charitable-Custom-Campaign-Receipt-Pages

Step 1: Add our function

As with the last two tutorials, this one starts with a PHP function which will run when the init hook is called within WordPress. init is a hook that happens early on while WordPress is loading, before the page has started rendering.

add_action( 'init', function() {
    // Our code will go in here.
} );

We are using an anonymous function here, which is fine as long as you are on a version of PHP greater than 5.2.

If you’re not sure how to add this to your site, check out our guide:

Step 2: Add the field to the Campaign editor

We can now add our “Donation Receipt Page” setting by registering a new field using the Campaign Fields API.

add_action( 'init', function() {

	/**
	 * Create a new field as an instance of `Charitable_Campaign_Field`.
	 *
	 * See all available arguments at:
	 *
	 * @https://github.com/Charitable/Charitable/blob/ef9a468fbdd6fa83307abe6ac0c38896f625cf45/includes/fields/class-charitable-campaign-field.php
	*/
	$campaign_field = new Charitable_Campaign_Field( 'donation_receipt_page', array(
		'label'      => 'Donation Receipt Page',
		'data_type'  => 'meta',
		'admin_form' => array(
			'type'     => 'select',
			'required' => false,
			'options'  => array(
				'default' => 'Use the default donation receipt page',
				'pages'   => array(
					'options' => charitable_get_pages_options(),
					'label'   => 'Pages',
				),
			),
			'default'  => 'default',
			'section'  => 'campaign-donation-options',
		),
                'show_in_export' => true,
	) );

	/**
	 * Now, we register our new field.
	 */
	charitable()->campaign_fields()->register_field( $campaign_field );

} );

This is the same approach that we used in the previous two tutorials, so if you read those this will look quite familiar to you. One new bit is how the field’s admin_form setting is set up:

'admin_form' => array(
	'type'     => 'select',
	'required' => false,
	'options'  => array(
		'default' => 'Use the default donation receipt page',
		'pages'   => array(
			'options' => charitable_get_pages_options(),
			'label'   => 'Pages',
		),
	),
	'default'  => 'default',
	'section'  => 'campaign-donation-options',
),

The type is set to select, which means that a dropdown select field will be used. Select fields require a set of options, which are passed as an array. Our array includes first of all a default choice, followed by a list of pages, retrieved using the charitable_get_pages_options() function. If you’re familiar with HTML, the way this is structured means that the options array inside pages creates an optgroup element, with label set as the label.

Our new Donation Receipt Page field

Step 3: Override the default donation receipt page

Within Charitable, the donation receipt URL for a particular donation is retrieved like this:

charitable_get_permalink( 'donation_receipt_page', array(
    'donation_id' => $donation_id,
) );

This function in turn uses the Endpoint API, which provides a structured way to deal with important endpoints within Charitable, such as campaigns, donation pages, the login page and the donation receipt page.

What is important for our case is that the returned permalink can be filtered. In the case of the donation receipt page, the filter to use is charitable_permalink_donation_receipt_page. It provides two parameters:

  • $default – The default permalink to be used. We will fall back to this if the campaign has not set a custom receipt page, or if it’s using the default.
  • $args – An array containing the donation ID.

Step 3a: Create the outline of the callback function

First of all, let’s see what the structure of our callback function will look like:

/**
 * Filter the page to redirect the donor to after making their donation.
 *
 * @param  string $default The endpoint's URL.
 * @param  array  $args    Mixed set of arguments.
 * @return string
 */
add_filter( 'charitable_permalink_donation_receipt_page', function( $default, $args ) {

   // Code goes here.

}, 10, 2 } );

As you can see, we are defining an anonymous function that is hooked into the charitable_permalink_donation_receipt_page filter. Importantly, our last line sets the callback function to operate with priority 10 (the default) and receive 2 parameters.

Step 3b: Get the campaign for the donation receipt

The $args parameter will include a donation_id property. We use this to get a Charitable_Donation object, and in turn use that to get the Charitable_Campaign object:

/**
 * Get the donation object.
 */
$donation_id = isset( $args['donation_id'] ) ? $args['donation_id'] : get_the_ID();
$donation    = charitable_get_donation( $donation_id );

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

Step 3c: Get the campaign’s donation receipt page

Now that we have a Charitable_Campaign object, we can get the donation receipt page setting for the campaign with the get() method:

/**
 * Get the campaign's donation receipt page.
 */
$receipt_page = $campaign->get( 'donation_receipt_page' );

Step 3d: Check whether to return the default receipt URL

Remember that you can set the campaign to use the default receipt. It’s also possible that you haven’t updated your campaign since adding the Donation Receipt Page setting, in which case the $receipt_page variable will be false. If either of these is the case, we will return the $default variable since we don’t have a custom receipt for this campaign:

/**
 * If we haven't set a donation receipt page or we chose
 * the default option, return the default.
 */
if ( ! $receipt_page || 'default' == $receipt_page ) {
    return $default;
}

Step 3e: Return the custom receipt URL

If we’re still around at this point, it means that a custom receipt page is set for this campaign. All that’s left to do is to get the permalink for that page and then append the donation_id to it, as well as donation_receipt. The resulting URL will look like this:

https://mysite.com/my-custom-receipt-page/?donation_id=123&donation_receipt=1

Here’s how we do that:

/**
 * Get the permalink for the receipt page and then append
 * the donation_id and donation_receipt arguments to it.
 */
$receipt_page_url = get_permalink( $receipt_page );
$receipt_page_url = add_query_arg(
	array(
		'donation_id'      => $donation_id,
		'donation_receipt' => 1,
	),
	$receipt_page_url
);

/**
 * Return the escaped URL.
 */
return esc_url_raw( $receipt_page_url );

get_permalink is a core WordPress plugin used to get the URL for a particular page or post. We use that as the basis for our URL, and then append the required query arguments to it with add_query_arg. Finally, we return it as an escaped value with esc_url_raw.

Extra Step: Set up your custom receipt page

This solution allows you to use any page as a donation receipt page. Chances are, you would like to show information about the donation to the donor when they land on the receipt. To include this, you can use the [donation_receipt] shortcode; it will show the dynamic receipt information that is normally shown on Charitable receipts.

Bonus ideas for customizing the donation receipt page

We’ve seen here how to customize the donation receipt page on a per-campaign basis. But what if you would like to use a different donation receipt page based on a different factor?

Over on our Code Snippets library, we have a couple snippets available that show you how you can use a different donation receipt in other scenarios:

Got an idea for another tutorial?

If you have an idea for another tutorial, I’d love to hear it! Leave a comment below or get in touch via our Support page.

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