Created
April 15, 2021 04:51
-
-
Save ipokkel/0a6538924088f2451fc5259ff09decdf to your computer and use it in GitHub Desktop.
This recipe removes the default PMPro Cancel on Next Payment date email message and adds the !!access_expire_date!! email shortcode for the Email Templates Admin Editor.
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 removes the cancel email filter for Cancel on Next Payment Date | |
* and creates the shortcode !!access_expire_date!! that can be used in the | |
* | |
* 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/ | |
*/ | |
// Only remove filter if Email Templates Editor is active | |
function remove_pmproconpd_email_filter_for_cancel_email() { | |
if ( function_exists( 'pmproconpd_pmpro_before_change_membership_level' ) && function_exists( 'pmproet_email_data' ) ) { | |
remove_filter( 'pmpro_email_body', 'pmproconpd_pmpro_email_body' ); | |
} | |
} | |
add_action( 'init', 'remove_pmproconpd_email_filter_for_cancel_email' ); | |
// Creates !!access_expire_date!! that can be used in email template | |
function my_pmproet_pmproconpd_access_expire_date( $data, $email ) { | |
if ( function_exists( 'pmproconpd_pmpro_before_change_membership_level' ) ) { | |
global $pmpro_next_payment_timestamp; | |
// Only filter the 'cancel' template and | |
if ( 'cancel' === $email->template && ! empty( $pmpro_next_payment_timestamp ) ) { | |
// Get user object | |
$euser = get_user_by( 'email', $email->email ); | |
if ( ! empty( $euser ) ) { | |
// Is the date in the future? | |
if ( $pmpro_next_payment_timestamp - current_time( 'timestamp' ) > 0 ) { | |
$expiry_date = date_i18n( get_option( 'date_format' ), $pmpro_next_payment_timestamp ); | |
} | |
} | |
} | |
} | |
if ( ! $expiry_date ) { | |
$data['access_expire_date'] = ''; // set default if no data available for next payment timestamp | |
} else { | |
$data['access_expire_date'] = $expiry_date; | |
} | |
return $data; | |
} | |
add_filter( 'pmpro_email_data', 'my_pmproet_pmproconpd_access_expire_date', 10, 2 ); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment