Skip to content

Instantly share code, notes, and snippets.

@MaryOJob
Last active August 11, 2023 11:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MaryOJob/87f5a7a4988647691d7d92f75fa7fe8e to your computer and use it in GitHub Desktop.
Save MaryOJob/87f5a7a4988647691d7d92f75fa7fe8e to your computer and use it in GitHub Desktop.
Show donations made via PMPro Donations Add-On on a separate line on the PMPro Invoice and Email Invoice sent
<?php // do not copy this line
// Copy from below here...
/**
* Example of how to use pmpro_get_price_parts filter alongside PMPro Donations
*
* 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_custom_get_price_parts( $price_parts, $invoice ) {
if ( ! function_exists( 'pmprodon_get_price_components' ) ) {
// PMPro donations not installed.
return;
}
$donation_price_components = pmprodon_get_price_components( $invoice );
$subtotal = $invoice->total;
$donation_amount = floatval( $donation_price_components['donation'] );
$membership_amount = $subtotal - $donation_amount;
$price_parts[ 'subtotal' ] = array(
'label' => 'Subtotal',
'value' => pmpro_escape_price( pmpro_formatPrice( $subtotal ) ),
);
$price_parts[ 'sub_element_membership' ] = array(
'label' => 'Membership Price',
'value' => pmpro_escape_price( pmpro_formatPrice( $membership_amount ) ),
);
$price_parts[ 'sub_element_donation' ] = array(
'label' => 'Donation',
'value' => pmpro_escape_price( pmpro_formatPrice( $donation_amount ) ),
);
return $price_parts;
}
add_filter( 'pmpro_get_price_parts', 'my_custom_get_price_parts', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment