Last active
November 29, 2024 04:33
-
-
Save ipokkel/322142d1f23d4de57cafaea4ca7ce2eb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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'] = ''; | |
$membership_id = $email->data['membership_id']; | |
$level = pmpro_getLevel( $membership_id ); | |
// Get member's order and check for donations | |
$member_order = new MemberOrder(); | |
$member_order->getLastMemberOrder( get_current_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