Last active
October 20, 2022 16:08
-
-
Save sc0ttkclark/e677afa0a3676c8e64c0833702e6e9e8 to your computer and use it in GitHub Desktop.
This snippet enables a custom template to be used for when a member completes checkout for an addon. Look for "Checkout - Paid - Addon" in the template list. REQUIRES: PMPro, PMPro Addon Packages, and PMPro Email Templates Add On
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 | |
/** | |
* Register the custom checkout template for addon package purchases. | |
* | |
* @param array $templates The list of templates. | |
* | |
* @return array The list of templates. | |
*/ | |
function my_addon_checkout_template_register_template( $templates ) { | |
$templates['checkout_addon'] = array( | |
'subject' => __( 'Your addon confirmation for !!sitename!!', 'pmproet' ), | |
'description' => __( 'Checkout - Paid - Addon', 'pmproet'), | |
); | |
return $templates; | |
} | |
add_filter( 'pmproet_templates', 'my_addon_checkout_template_register_template' ); | |
/** | |
* Set the custom checkout template for addon package purchases. | |
* | |
* @param string $template The template to use for the email. | |
* | |
* @return string The template to use for the email. | |
*/ | |
function my_addon_checkout_template_set_template( $template ) { | |
$templates_to_override = [ | |
'checkout_paid', | |
'checkout_check', | |
'checkout_express', | |
'checkout_free', | |
]; | |
// We should only override the template we want to. | |
if ( ! in_array( $template, $templates_to_override, true ) ) { | |
return $template; | |
} | |
// Check if the addon ID is set. | |
if ( empty( $_REQUEST['ap'] ) ) { | |
return $template; | |
} | |
return 'checkout_addon'; | |
} | |
add_filter( 'pmpro_email_template', 'my_addon_checkout_template_set_template' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment