Created
October 23, 2024 14:41
-
-
Save ipokkel/e63540b6aea514f48d7a38d3455b02e6 to your computer and use it in GitHub Desktop.
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 | |
/** | |
* Give membership access to users with pending "Pay by Check" orders. | |
* | |
* 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 pmpro_give_pending_pay_by_check_access( $hasaccess, $post, $user, $levels ) { | |
// Skip if the user already has access. | |
if ( $hasaccess ) { | |
return $hasaccess; | |
} | |
// Get the required membership level IDs for the post. | |
$post_level_ids = wp_list_pluck( $levels, 'id' ); | |
// Get the last order paid by check. | |
$order = new MemberOrder(); | |
$order->getLastMemberOrder( $user->ID, 'pending', '', 'check' ); | |
// Do we have an order? | |
if ( empty( $order ) ) { | |
return $hasaccess; | |
} | |
$oder_level_id = $order->membership_id; | |
// Does the level in the order have access to this post? | |
if ( in_array( $oder_level_id, $post_level_ids, true ) ) { | |
// Give the user access to the post. | |
$hasaccess = true; | |
} | |
return $hasaccess; | |
} | |
add_filter( 'pmpro_has_membership_access_filter', 'pmpro_give_pending_pay_by_check_access', 10, 4 ); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment