Created
February 26, 2021 19:29
-
-
Save ipokkel/daea9c04413bcd167937f05b4cc1a0b6 to your computer and use it in GitHub Desktop.
This recipe will add some shortcodes to emails.
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 | |
/** | |
* This recipe will add some shortcodes to emails. | |
* | |
* by default the $data array that controls the email shortcodes is loaded | |
* conditionally, depending on the type of email being sent. This will | |
* add certain fields to emails if they are not available for that email template. | |
* | |
* 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_custom_email_data_shortcodes( $data, $email ) { | |
$user = get_user_by( 'email', $data['user_email'] ); | |
global $wpdb; | |
$invoice = new MemberOrder(); | |
$sql = "SELECT id FROM $wpdb->pmpro_membership_orders WHERE user_id = $user->ID ORDER BY timestamp DESC LIMIT 1"; | |
$id = $wpdb->get_var( $sql ); | |
$invoice->getMemberOrderByID( $id ); | |
if ( ! isset( $data['invoice_total'] ) && empty( $data['invoice_total'] ) ) { | |
$data['invoice_total'] = pmpro_formatPrice( $invoice->total ); | |
} | |
if ( ! isset( $data['invoice_id'] ) && empty( $data['invoice_id'] ) ) { | |
$data['invoice_id'] = $invoice->code; | |
} | |
if ( ! isset( $data['invoice_date'] ) && empty( $data['invoice_date'] ) ) { | |
$data['invoice_date'] = date_i18n( get_option( 'date_format' ), $invoice->timestamp ); | |
} | |
if ( ! isset( $data['billing_address'] ) && empty( $data['billing_address'] ) ) { | |
$data['billing_address'] = pmpro_formatAddress( | |
$invoice->billing->name, | |
$invoice->billing->street, | |
'', //address 2 | |
$invoice->billing->city, | |
$invoice->billing->state, | |
$invoice->billing->zip, | |
$invoice->billing->country, | |
$invoice->billing->phone | |
); | |
} | |
return $data; | |
} | |
add_filter( 'pmpro_email_data', 'my_pmpro_custom_email_data_shortcodes', 10, 2 ); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment