Skip to content

Instantly share code, notes, and snippets.

@ipokkel
Last active March 25, 2025 10:12
Show Gist options
  • Select an option

  • Save ipokkel/322142d1f23d4de57cafaea4ca7ce2eb to your computer and use it in GitHub Desktop.

Select an option

Save ipokkel/322142d1f23d4de57cafaea4ca7ce2eb to your computer and use it in GitHub Desktop.
<?php
/**
* Add donation email vairable and reset membership cost value to exclude donation.
*
* You can add this recipe to your site by creating a custom plugin
* or using the Code Snippets plugin available for free in the WordPress repository.
* Read this companion article for step-by-step directions on either method.
* https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
function my_pmpro_email_data_membership_cost_donation( $data, $email ) {
$data['donation'] = '';
// Check if email data contains membership_id.
if ( empty( $email->data['membership_id'] ) ) {
return $data;
}
$membership_id = $email->data['membership_id'];
$level = pmpro_getLevel( $membership_id );
// Get user ID from email if available, otherwise use current user.
$user = get_user_by( 'email', $email->data['user_email'] );
$user_id = $user->ID;
// Get member's order and check for donations.
$member_order = new MemberOrder();
$member_order->getLastMemberOrder( $user_id, 'success', $membership_id );
if ( ! empty( $member_order->id ) && function_exists( 'pmprodon_get_price_components' ) ) {
$donation = pmprodon_get_price_components( $member_order );
if ( ! empty( $donation['donation'] ) ) {
$donation_amount = pmpro_formatPrice( $donation['donation'] );
$data['donation'] = 'Thank you for your donation of <strong>' . $donation_amount . '</strong>';
// Set membership.
if ( ! empty( $level ) ) {
$data['membership_cost'] = pmpro_getLevelCost( $level, true );
}
}
}
return $data;
}
add_filter( 'pmpro_email_data', 'my_pmpro_email_data_membership_cost_donation', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment