| 1 |
<?php |
| 2 |
/** |
| 3 |
* This template is used to display the donation summary with [give_receipt] |
| 4 |
*/ |
| 5 |
|
| 6 |
use Give\Helpers\Frontend\Shortcode as ShortcodeUtils; |
| 7 |
|
| 8 |
global $give_receipt_args, $donation; |
| 9 |
|
| 10 |
// Validation: Ensure $donation var is set. |
| 11 |
if ( empty( $donation ) ) { |
| 12 |
$donation = ! empty( $give_receipt_args['id'] ) ? get_post( $give_receipt_args['id'] ) : 0; |
| 13 |
} |
| 14 |
|
| 15 |
/** |
| 16 |
* Double-Validation: Check for $donation global. |
| 17 |
* |
| 18 |
* @since 3.4.0 Add additional validations to check if the form is valid and has the 'published' status. |
| 19 |
*/ |
| 20 |
if ( ! is_object($donation) || ! ShortcodeUtils::isValidDonation($donation->ID)) { |
| 21 |
Give_Notices::print_frontend_notice( __( 'The specified receipt ID appears to be invalid.', 'give' ) ); |
| 22 |
return; |
| 23 |
} |
| 24 |
|
| 25 |
$donation_id = $donation->ID; |
| 26 |
$donation_number = Give()->seq_donation_number->get_serial_code( $donation_id ); |
| 27 |
$form_id = give_get_payment_meta( $donation_id, '_give_payment_form_id', true ); |
| 28 |
$form_name = give_get_donation_form_title( $donation_id ); |
| 29 |
$user = give_get_payment_meta_user_info( $donation_id ); |
| 30 |
$email = give_get_payment_user_email( $donation_id ); |
| 31 |
$status = $donation->post_status; |
| 32 |
$status_label = give_get_payment_status( $donation_id, true ); |
| 33 |
$company_name = give_get_payment_meta( $donation_id, '_give_donation_company', true ); |
| 34 |
|
| 35 |
// Update donor name, if title prefix is set. |
| 36 |
$full_name = give_get_donor_name_with_title_prefixes( $user['title'], "{$user['first_name']} {$user['last_name']}" ); |
| 37 |
|
| 38 |
/** |
| 39 |
* Generate Donation Receipt Arguments. |
| 40 |
* |
| 41 |
* Added donation receipt array to global variable $give_receipt_args to |
| 42 |
* manage it from single variable |
| 43 |
* |
| 44 |
* @since 1.8.8 |
| 45 |
*/ |
| 46 |
$give_receipt_args['donation_receipt']['donor'] = [ |
| 47 |
'name' => __( 'Donor', 'give' ), |
| 48 |
'value' => esc_html( give_strip_shortcodes_deep( $full_name ) ), |
| 49 |
'display' => $give_receipt_args['donor'], |
| 50 |
]; |
| 51 |
|
| 52 |
/** |
| 53 |
* Show Company name on Donation receipt Page |
| 54 |
* |
| 55 |
* @since 2.0.7 |
| 56 |
* |
| 57 |
* @param bool show/hide company name in donation receipt page. |
| 58 |
* |
| 59 |
* @return bool show/hide company name in donation receipt page. |
| 60 |
*/ |
| 61 |
$give_receipt_args['donation_receipt']['company_name'] = [ |
| 62 |
'name' => __( 'Company Name', 'give' ), |
| 63 |
'value' => esc_html( give_strip_shortcodes_deep( $company_name ) ), |
| 64 |
// Do not show company field if empty |
| 65 |
'display' => empty( $company_name ) ? false : $give_receipt_args['company_name'], |
| 66 |
]; |
| 67 |
|
| 68 |
$give_receipt_args['donation_receipt']['date'] = [ |
| 69 |
'name' => __( 'Date', 'give' ), |
| 70 |
'value' => date_i18n( give_date_format(), strtotime( give_get_payment_completed_date( $donation_id ) ) ), |
| 71 |
'display' => $give_receipt_args['date'], |
| 72 |
]; |
| 73 |
|
| 74 |
$give_receipt_args['donation_receipt']['total_donation'] = [ |
| 75 |
'name' => __( 'Total Donation', 'give' ), |
| 76 |
'value' => give_donation_amount( |
| 77 |
$donation_id, |
| 78 |
[ |
| 79 |
'currency' => true, |
| 80 |
'amount' => true, |
| 81 |
'type' => 'receipt', |
| 82 |
] |
| 83 |
), |
| 84 |
'display' => $give_receipt_args['price'], |
| 85 |
]; |
| 86 |
|
| 87 |
$give_receipt_args['donation_receipt']['donation'] = [ |
| 88 |
'name' => __( 'Donation', 'give' ), |
| 89 |
'value' => $form_name, |
| 90 |
'display' => true, |
| 91 |
]; |
| 92 |
|
| 93 |
$give_receipt_args['donation_receipt']['donation_status'] = [ |
| 94 |
'name' => __( 'Donation Status', 'give' ), |
| 95 |
'value' => esc_attr( $status_label ), |
| 96 |
'display' => $give_receipt_args['payment_status'], |
| 97 |
]; |
| 98 |
|
| 99 |
$give_receipt_args['donation_receipt']['donation_id'] = [ |
| 100 |
'name' => __( 'Donation ID', 'give' ), |
| 101 |
'value' => $donation_number, |
| 102 |
'display' => $give_receipt_args['payment_id'], |
| 103 |
]; |
| 104 |
|
| 105 |
$give_receipt_args['donation_receipt']['payment_method'] = [ |
| 106 |
'name' => __( 'Payment Method', 'give' ), |
| 107 |
'value' => give_get_gateway_checkout_label( give_get_payment_gateway( $donation_id ) ), |
| 108 |
'display' => $give_receipt_args['payment_method'], |
| 109 |
]; |
| 110 |
|
| 111 |
/** |
| 112 |
* Extend Give Donation Receipt |
| 113 |
* |
| 114 |
* You can easily extend the donation receipt argument using the filter give_donation_receipt_args |
| 115 |
* |
| 116 |
* @params array $give_receipt_args['donation_receipt'] Array of arguments for Donation Receipt. |
| 117 |
* @params int $donation_id Donation ID. |
| 118 |
* @params int $form_id Donation Form ID. |
| 119 |
* |
| 120 |
* @since 1.8.8 |
| 121 |
*/ |
| 122 |
$give_receipt_args['donation_receipt'] = apply_filters( 'give_donation_receipt_args', $give_receipt_args['donation_receipt'], $donation_id, $form_id ); |
| 123 |
|
| 124 |
// When the donation were made through offline donation, We won't show receipt and payment status though. |
| 125 |
if ( 'offline' === give_get_payment_gateway( $donation_id ) && 'pending' === $status ) { |
| 126 |
|
| 127 |
/** |
| 128 |
* Before the offline donation receipt content starts. |
| 129 |
* |
| 130 |
* @since 1.8.14 |
| 131 |
* |
| 132 |
* @param Give_Payment $donation Donation object. |
| 133 |
* @param array $give_receipt_args Receipt Arguments. |
| 134 |
*/ |
| 135 |
do_action( 'give_receipt_before_offline_payment', $donation, $give_receipt_args ); |
| 136 |
?> |
| 137 |
<h2><?php echo apply_filters( 'give_receipt_offline_payment_heading', __( 'Your Donation is Almost Complete!', 'give' ) ); ?></h2> |
| 138 |
<div id="give_donation_receipt" class="<?php echo esc_attr( apply_filters( 'give_receipt_offline_payment_classes', 'give_receipt_offline_payment' ) ); ?>"> |
| 139 |
<?php |
| 140 |
// Instruction for offline donation. |
| 141 |
$offline_instruction = give_get_offline_payment_instruction( $form_id, true ); |
| 142 |
|
| 143 |
/** |
| 144 |
* Instruction for the offline donation. |
| 145 |
* |
| 146 |
* @since 1.8.14 |
| 147 |
* |
| 148 |
* @param string $offline_instruction Offline instruction content. |
| 149 |
* @param Give_Payment $donation Donation object. |
| 150 |
* @param integer $form_id Donation form id. |
| 151 |
*/ |
| 152 |
echo apply_filters( 'give_receipt_offline_payment_instruction', $offline_instruction, $donation, $form_id ); |
| 153 |
?> |
| 154 |
</div> |
| 155 |
<?php |
| 156 |
/** |
| 157 |
* After the offline donation content ends. |
| 158 |
* |
| 159 |
* @since 1.8.14 |
| 160 |
* |
| 161 |
* @param Give_Payment $donation Donation object. |
| 162 |
* @param array $give_receipt_args Receipt Arguments. |
| 163 |
*/ |
| 164 |
do_action( 'give_receipt_after_offline_payment', $donation, $give_receipt_args ); |
| 165 |
|
| 166 |
return; |
| 167 |
} |
| 168 |
|
| 169 |
// Show payment status notice based on shortcode attribute. |
| 170 |
if ( filter_var( $give_receipt_args['status_notice'], FILTER_VALIDATE_BOOLEAN ) ) { |
| 171 |
$notice_message = ''; |
| 172 |
$notice_type = 'warning'; |
| 173 |
|
| 174 |
switch ( $status ) { |
| 175 |
case 'publish': |
| 176 |
$notice_message = __( 'Payment Complete: Thank you for your donation.', 'give' ); |
| 177 |
$notice_type = 'success'; |
| 178 |
break; |
| 179 |
case 'pending': |
| 180 |
$notice_message = __( 'Payment Pending: Your donation is currently processing.', 'give' ); |
| 181 |
$notice_type = 'warning'; |
| 182 |
break; |
| 183 |
case 'refunded': |
| 184 |
$notice_message = __( 'Payment Refunded: Your donation has been refunded.', 'give' ); |
| 185 |
$notice_type = 'warning'; |
| 186 |
break; |
| 187 |
case 'preapproval': |
| 188 |
$notice_message = __( 'Payment Preapproved: Thank you for your donation.', 'give' ); |
| 189 |
$notice_type = 'warning'; |
| 190 |
break; |
| 191 |
case 'failed': |
| 192 |
$notice_message = __( 'Payment Failed: Please contact the site owner for assistance.', 'give' ); |
| 193 |
$notice_type = 'error'; |
| 194 |
break; |
| 195 |
case 'cancelled': |
| 196 |
$notice_message = __( 'Payment Cancelled: Your donation has been cancelled.', 'give' ); |
| 197 |
$notice_type = 'error'; |
| 198 |
break; |
| 199 |
case 'abandoned': |
| 200 |
$notice_message = __( 'Payment Abandoned: This donation has not been completed.', 'give' ); |
| 201 |
$notice_type = 'error'; |
| 202 |
break; |
| 203 |
case 'revoked': |
| 204 |
$notice_message = __( 'Payment Revoked: Please contact the site owner for assistance.', 'give' ); |
| 205 |
$notice_type = 'error'; |
| 206 |
break; |
| 207 |
} |
| 208 |
|
| 209 |
/** |
| 210 |
* Filters payment status notice for receipts. |
| 211 |
* |
| 212 |
* By default, a success, warning, or error notice appears on the receipt |
| 213 |
* with payment status. This filter allows the HTML markup |
| 214 |
* and messaging for that notice to be customized. |
| 215 |
* |
| 216 |
* @since 1.0 |
| 217 |
* |
| 218 |
* @param string $notice HTML markup for the default notice. |
| 219 |
* @param int $id Post ID where the notice is displayed. |
| 220 |
* @param string $status Payment status. |
| 221 |
* @param int $donation_id Donation ID. |
| 222 |
*/ |
| 223 |
echo apply_filters( 'give_receipt_status_notice', Give_Notices::print_frontend_notice( $notice_message, false, $notice_type ), $id, $status, $donation_id ); |
| 224 |
|
| 225 |
}// End if(). |
| 226 |
|
| 227 |
/** |
| 228 |
* Fires in the donation receipt shortcode, before the receipt main table. |
| 229 |
* |
| 230 |
* Allows you to add elements before the table. |
| 231 |
* |
| 232 |
* @since 1.0 |
| 233 |
* |
| 234 |
* @param object $donation Donation object. |
| 235 |
* @param array $give_receipt_args Receipt_argument. |
| 236 |
*/ |
| 237 |
do_action( 'give_payment_receipt_before_table', $donation, $give_receipt_args ); |
| 238 |
?> |
| 239 |
|
| 240 |
<table id="give_donation_receipt" class="give-table"> |
| 241 |
<thead> |
| 242 |
<?php |
| 243 |
/** |
| 244 |
* Fires in the donation receipt shortcode, before the receipt first header item. |
| 245 |
* |
| 246 |
* Allows you to add new <th> elements before the receipt first header item. |
| 247 |
* |
| 248 |
* @since 1.7 |
| 249 |
* |
| 250 |
* @param object $donation Donation object. |
| 251 |
* @param array $give_receipt_args Receipt_argument. |
| 252 |
*/ |
| 253 |
do_action( 'give_payment_receipt_header_before', $donation, $give_receipt_args ); |
| 254 |
?> |
| 255 |
<tr> |
| 256 |
<th scope="colgroup" colspan="2"> |
| 257 |
<span class="give-receipt-thead-text"><?php esc_html_e( 'Donation Receipt', 'give' ); ?></span> |
| 258 |
</th> |
| 259 |
</tr> |
| 260 |
<?php |
| 261 |
/** |
| 262 |
* Fires in the donation receipt shortcode, after the receipt last header item. |
| 263 |
* |
| 264 |
* Allows you to add new <th> elements after the receipt last header item. |
| 265 |
* |
| 266 |
* @since 1.7 |
| 267 |
* |
| 268 |
* @param object $donation Donation object. |
| 269 |
* @param array $give_receipt_args Receipt_argument. |
| 270 |
*/ |
| 271 |
do_action( 'give_payment_receipt_header_after', $donation, $give_receipt_args ); |
| 272 |
?> |
| 273 |
</thead> |
| 274 |
|
| 275 |
<tbody> |
| 276 |
<?php |
| 277 |
/** |
| 278 |
* Fires in the donation receipt shortcode, before the receipt first item. |
| 279 |
* |
| 280 |
* Allows you to add new <td> elements before the receipt first item. |
| 281 |
* |
| 282 |
* @since 1.7 |
| 283 |
* |
| 284 |
* @param object $donation Donation object. |
| 285 |
* @param array $give_receipt_args Receipt_argument. |
| 286 |
*/ |
| 287 |
do_action( 'give_payment_receipt_before', $donation, $give_receipt_args ); |
| 288 |
?> |
| 289 |
|
| 290 |
<?php foreach ( $give_receipt_args['donation_receipt'] as $receipt_item ) { ?> |
| 291 |
<?php if ( filter_var( $receipt_item['display'], FILTER_VALIDATE_BOOLEAN ) ) : ?> |
| 292 |
<tr> |
| 293 |
<td scope="row"><strong><?php echo $receipt_item['name']; ?></strong></td> |
| 294 |
<td><?php echo $receipt_item['value']; ?></td> |
| 295 |
</tr> |
| 296 |
<?php endif; ?> |
| 297 |
<?php } ?> |
| 298 |
|
| 299 |
<?php |
| 300 |
/** |
| 301 |
* Fires in the donation receipt shortcode, after the receipt last item. |
| 302 |
* |
| 303 |
* Allows you to add new <td> elements after the receipt last item. |
| 304 |
* |
| 305 |
* @since 1.7 |
| 306 |
* |
| 307 |
* @param object $donation Donation object. |
| 308 |
* @param array $give_receipt_args Receipt_argument. |
| 309 |
*/ |
| 310 |
do_action( 'give_payment_receipt_after', $donation, $give_receipt_args ); |
| 311 |
?> |
| 312 |
</tbody> |
| 313 |
</table> |
| 314 |
|
| 315 |
<?php |
| 316 |
/** |
| 317 |
* Fires in the donation receipt shortcode, after the receipt main table. |
| 318 |
* |
| 319 |
* Allows you to add elements after the table. |
| 320 |
* |
| 321 |
* @since 1.7 |
| 322 |
* |
| 323 |
* @param object $donation Donation object. |
| 324 |
* @param array $give_receipt_args Receipt_argument. |
| 325 |
*/ |
| 326 |
do_action( 'give_payment_receipt_after_table', $donation, $give_receipt_args ); |
| 327 |
?> |
| 328 |
|