"In Honor Of" Field for GiveWP Donations
Adds an optional "Donate in honor or memory of" field to GiveWP forms, saves it with the donation, shows it on the donation details screen and offers an {honoree} email tag.
Opens WPIDE on
Code
$wpide_label = 'Donate in honor or memory of (optional)'; // Field label.
add_action( 'give_after_donation_levels', function ( $form_id ) use ( $wpide_label ) {
$id = 'wpide-honoree-' . (int) $form_id;
?>
<p class="form-row form-row-wide wpide-give-honoree">
<label class="give-label" for="<?php echo esc_attr( $id ); ?>"><?php echo esc_html( $wpide_label ); ?></label>
<input type="text" class="give-input" name="wpide_honoree" id="<?php echo esc_attr( $id ); ?>" maxlength="120" autocomplete="off">
</p>
<?php
} );
add_action( 'give_insert_payment', function ( $payment_id ) {
if ( empty( $_POST['wpide_honoree'] ) || ! function_exists( 'give_update_meta' ) ) { // phpcs:ignore WordPress.Security.NonceVerification -- GiveWP verifies its own form nonce.
return;
}
give_update_meta( $payment_id, 'wpide_honoree', sanitize_text_field( wp_unslash( $_POST['wpide_honoree'] ) ) ); // phpcs:ignore WordPress.Security.NonceVerification
} );
add_action( 'give_payment_view_details', function ( $payment_id ) {
$honoree = function_exists( 'give_get_meta' ) ? give_get_meta( $payment_id, 'wpide_honoree', true ) : '';
if ( $honoree ) {
echo '<div class="postbox"><h3 class="hndle">' . esc_html__( 'Tribute' ) . '</h3><div class="inside"><p>' . esc_html( $honoree ) . '</p></div></div>';
}
} );
add_action( 'give_add_email_tags', function () {
if ( ! function_exists( 'give_add_email_tag' ) ) {
return;
}
give_add_email_tag( 'honoree', __( 'The person the donation honors' ), function ( $tag_args ) {
$payment_id = isset( $tag_args['payment_id'] ) ? (int) $tag_args['payment_id'] : 0;
return $payment_id ? esc_html( (string) give_get_meta( $payment_id, 'wpide_honoree', true ) ) : '';
} );
} );
Notes
Use {honoree} in GiveWP email templates. Works with the legacy and multi-step form templates; forms made with GiveWP 3's visual builder have their own custom field blocks.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.