Forked from ipokkel/custom-level-confirmation-message-for-pmpro-approvals.php
Last active
July 14, 2023 19:47
-
-
Save MaximilianoRicoTabo/f9669d90a41d3d5f379e8f9716562cef 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.
This file contains hidden or 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 | |
/** | |
* 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; | |
$users_level = pmpro_getMembershipLevelForUser( $current_user->ID ); | |
$level_id = $users_level->ID; | |
$approval_status = PMPro_Approvals::getUserApprovalStatus($current_user->ID, $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' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment