Home / Admin / Custom Receipt Page
Duplicate Snippet

Embed Snippet on Your Site

Custom Receipt Page

Redirect to custom receipt or another page after a donation is completed. Can be per campaign based.

Code Preview
php
<?php
add_filter( 'charitable_permalink_donation_receipt_page', 'example_charitable_permalink_donation_receipt', 999, 2 );
function example_charitable_permalink_donation_receipt( $value, $args ) {
	// The $value is the URL of the donation receipt page or whatever URL you want the user to go after a successful donation.
	// The $args array contains the arguments passed to the filter, which most of the time will be only a donation_id.
	if ( ! empty( $args['donation_id'] ) ) {
		$donation_id  = intval( $args['donation_id'] );
		$campaign_ids = charitable_get_table( 'campaign_donations' )->get_campaigns_for_donation( $donation_id );
		$campaign_id  = ! empty( $campaign_ids[0] ) ? $campaign_ids[0] : false;
		// If the donation is associated with a certain campaign id, redirect the user to a custom page.
		if ( 173 === intval( $campaign_id ) ) {
			return home_url( '/custom-page/' );
		}
	}
	// Otherwise, return the default value.
	return $value;
}

Comments

Add a Comment