Created
February 13, 2023 07:58
-
-
Save ipokkel/813fd54737dfabd7d334ed26fa2638b6 to your computer and use it in GitHub Desktop.
Set a custom PMPro Confirmation Message. This example recipe include the ability to customize the confirmation message if the member checked out using the Check payment gateway.
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 | |
/** | |
* Customize the default confirmation message shown to new members. | |
* | |
* This recipe also adds a unique custom message if the Check gateway was used at checkout. | |
* | |
* 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/ | |
*/ | |
// remove the default confirmation text | |
remove_filter( 'pmpro_confirmation_message', 'pmpro_pmpro_confirmation_message' ); | |
// add new confirmation text | |
function my_pmpro_custom_confirmation_message( $message ) { | |
global $current_user; | |
// Set default message. | |
$message = ''; | |
$morder = new MemberOrder(); | |
$morder->getLastMemberOrder( $current_user->ID, null ); | |
// Let's check i the last order used the Check gateway and is still pending. | |
if ( $morder->status == 'pending' && $morder->gateway == 'check' ) { | |
// Add a custom message if user checked out using the Check gateway. | |
$message .= '<p>This is a new confirmation message if the Check gateway was used at checkout.</p>'; | |
} else { | |
// Add a custom message if user checked out using any other gateway. | |
$message .= '<p>This is a new confirmation message.</p>'; | |
} | |
return $message; | |
} | |
// Priority 15 to run after the default confirmation message. Priority must be higher than 10. | |
add_filter( 'pmpro_confirmation_message', 'my_pmpro_custom_confirmation_message', 15, 1 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment