Skip to content

Instantly share code, notes, and snippets.

@JarrydLong
Forked from kimwhite/add-tax-pmpro-emails.php
Last active March 13, 2024 10:00
Show Gist options
  • Save JarrydLong/7a2eecf23e7d7083a1dc6622aaf2f08d to your computer and use it in GitHub Desktop.
Save JarrydLong/7a2eecf23e7d7083a1dc6622aaf2f08d to your computer and use it in GitHub Desktop.
Email Variable Add !!tax!! and !!subtotal!! variable for Paid Memberships Pro email templates
<?php
/**
* Adds an email variable !!tax!! to Paid Memberships Pro emails.
* Only works for email templates that has the !!invoice_id!! variable available.
* Use the Email Templates Admin Editor to add !!tax!! to your email templates.
* Follow this guide to add this code to your site: https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*
* Difficulty: Easy
*/
function my_pmpro_email_variable( $data, $email ) {
if ( isset( $data['invoice_id'] ) && $data['billing_country'] == 'AU' ) {
$order = new MemberOrder( $data['invoice_id'] );
$total = $order->total;
if( (int)$order->membership_id == 2 ) {
$amount_before_tax = $total / 1.15; //Assuming 15% tax for level 2
} else if( (int)$order->membership_id == 3 ) {
$amount_before_tax = $total / 1.20; //Assuming 20% tax for level 3
} else {
//Assume no tax
$amount_before_tax = $total;
}
$tax = $total - $amount_before_tax;
$data['tax'] = pmpro_formatPrice( $tax );
} else {
$data['tax'] = pmpro_formatPrice( 0 );
}
return $data;
}
add_filter( 'pmpro_email_data', 'my_pmpro_email_variable', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment