Home / Admin / Add Custom Field From Donation Form On The Receipt Page
Duplicate Snippet

Embed Snippet on Your Site

Add Custom Field From Donation Form On The Receipt Page

This is an example of how to show a field data someone entered in their donation form to be displayed on a receipt page. The below is a template file you will need to add your child theme and you will need to make sure the custom field "slug" or ID matches to how you defined in elsewhere in your code.

Currently this is the best place to custom information although you can check out these templates as well which may show information on the receipt page depending on your configuration:

donation-receipt/offline-payment-instructions.php
donation-receipt/details.php

Code Preview
php
<?php
/**
 * Displays the donation summary ( updated to show custom fields )
 *
 * Override this template by copying it to yourtheme/charitable/donation-receipt/summary.php
 *
 * @author  WP Charitable LLC
 * @package Charitable/Templates/Donation Receipt
 * @since   1.0.0
 * @version 1.4.7
 */
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}
/* @var Charitable_Donation */
$donation = $view_args['donation'];
$amount   = $donation->get_total();
?>
<dl class="donation-summary">
	<dt class="donation-id"><?php _e( 'Donation Number:', 'charitable' ); ?></dt>
	<dd class="donation-summary-value"><?php echo $donation->get_number(); ?></dd>
	<dt class="donation-date"><?php _e( 'Date:', 'charitable' ); ?></dt>
	<dd class="donation-summary-value"><?php echo $donation->get_date(); ?></dd>
	<dt class="donation-total"> <?php _e( 'Total:', 'charitable' ); ?></dt>
	<dd class="donation-summary-value">
	<?php
		/**
		 * Filter the total donation amount.
		 *
		 * @since  1.5.0
		 *
		 * @param  string              $amount   The default amount to display.
		 * @param  float               $total    The total, unformatted.
		 * @param  Charitable_Donation $donation The Donation object.
		 * @param  string              $context  The context in which this is being shown.
		 * @return string
		 */
		echo apply_filters( 'charitable_donation_receipt_donation_amount', charitable_format_money( $amount ), $amount, $donation, 'summary' )
	?>
	</dd>
	<dt class="donation-method"><?php _e( 'Payment Method:', 'charitable' ); ?></dt>
	<dd class="donation-summary-value"><?php echo $donation->get_gateway_label(); ?></dd>
	<!-- Example Here Of Showing Custom Field That Was Entered by The Doantion Form -->
	<!-- "Company" is the slug used when you defined it with the Charitable_Donation_Field object.. in our example it is "company" -->
	<dt class="donation-method"><?php _e( 'Company:', 'charitable' ); ?></dt>
	<dd class="donation-summary-value"><?php echo $donation->get( 'company' ); ?></dd>
</dl>

Comments

Add a Comment