Last active
May 22, 2025 10:24
-
-
Save ipokkel/da1cfaaf0326c7170a939699324049ac to your computer and use it in GitHub Desktop.
Adds payment method variable to Paid Memberships Pro emails that can be included using the Paid Memberships Pro Email Templates Add On
This file contains hidden or 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 | |
/** | |
* Adds !!payment_method!! variable to be used with the | |
* Paid Memberships Pro Email Templates Add On. | |
* This data will be available for all Paid Memberships Pro emails. | |
* Add the below code to your PMPro Customizations Plugin and | |
* edit the email templates you want to add this to. | |
*/ | |
add_filter( 'pmpro_email_data', 'add_payment_method_to_pmpro_emails', 10, 2 ); | |
function add_payment_method_to_pmpro_emails( $data, $email ) { | |
$payment_method = 'N/A'; // default string if no data is available. | |
$invoice_id = null; | |
// Get payment method from invoice | |
if ( isset( $data['invoice_id'] ) ) { | |
$invoice_id = $data['invoice_id']; | |
} | |
if ( ! empty( $invoice_id ) ) { | |
$invoice = new MemberOrder( $invoice_id ); | |
$payment_method = $invoice->gateway; | |
if ( false !== strpos( $payment_method, 'paypal' ) ) { | |
$payment_method = 'PayPal'; | |
$data['payment_method'] = $payment_method; | |
return $data; | |
} elseif ( false !== strpos( $payment_method, 'check' ) ) { | |
$payment_method = 'Check'; | |
$data['payment_method'] = $payment_method; | |
return $data; | |
} elseif ( false === strpos( $payment_method, 'free' ) ) { | |
$payment_method = 'Credit Card'; | |
$data['payment_method'] = $payment_method; | |
return $data; | |
} | |
} | |
$data['payment_method'] = ucwords( $payment_method ); | |
return $data; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment