Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ipokkel/23997ac1438f706807e1cc94d9cdc175 to your computer and use it in GitHub Desktop.
Save ipokkel/23997ac1438f706807e1cc94d9cdc175 to your computer and use it in GitHub Desktop.
Keep the custom messages set for each level under Membership >> Membership Levels and combine it with the PMPro Approvals status.
<?php
/**
* Create a custom confirmation for Approvals Add On.
*
* 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 modify_status_from_confirmation_message( $confirmation_message, $pmpro_invoice ) {
// Bail if necessary
if ( ! class_exists( 'PMPro_Approvals' ) ) {
return $confirmation_message;
}
global $current_user, $wpdb;
$approval_status = null;
$approval_status = PMPro_Approvals::getUserApprovalStatus();
$users_level = pmpro_getMembershipLevelForUser( $current_user->ID );
$level_id = $users_level->ID;
//if current level does not require approval keep confirmation message the same.
if ( ! PMPro_Approvals::requiresApproval( $level_id ) ) {
return $confirmation_message;
}
if ( ! empty( $approval_status ) ) {
$confirmation_message = '<p>' . sprintf( __( 'Thank you for your membership to %1$s. Your %2$s membership status is: <b>%3$s</b>.', 'pmpro-approvals' ), get_bloginfo( 'name' ), $current_user->membership_level->name, $approval_status ) . '</p>';
}
$level_message = $wpdb->get_var( $wpdb->prepare( "SELECT l.confirmation FROM $wpdb->pmpro_membership_levels l LEFT JOIN $wpdb->pmpro_memberships_users mu ON l.id = mu.membership_id WHERE mu.status = 'active' AND mu.user_id = %d LIMIT 1", $current_user->ID ) );
if ( ! empty( $level_message ) ) {
$confirmation_message .= "\n" . stripslashes( $level_message ) . "\n";
}
$confirmation_message .= '<p>' . __( 'Below are details about your membership account:' ) . '</p>';
return $confirmation_message;
}
function my_pmpro_approvals_change_approval_confirmation_hook() {
// Swop only if Approvals is active and custom function exist.
if ( class_exists( 'PMPro_Approvals' ) && function_exists( 'modify_status_from_confirmation_message' ) ) {
remove_filter( 'pmpro_confirmation_message', array( 'PMPro_Approvals', 'pmpro_confirmation_message' ) );
add_filter( 'pmpro_confirmation_message', 'modify_status_from_confirmation_message', 10, 2 );
}
}
add_action( 'init', 'my_pmpro_approvals_change_approval_confirmation_hook' );
@ipokkel
Copy link
Author

ipokkel commented Jul 22, 2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment