Skip to content

Instantly share code, notes, and snippets.

@wplit
Last active July 4, 2024 10:04
Show Gist options
  • Save wplit/505e34e22261c88bfbf2e401cb000ab5 to your computer and use it in GitHub Desktop.
Save wplit/505e34e22261c88bfbf2e401cb000ab5 to your computer and use it in GitHub Desktop.
check user status matches in specific membership level (RCP)
<?php
/* custom function for checking status of user in membership (add to code snippets or child theme)
* @return bool True if user has the status in that memberhip.
*/
function rcp_member_status( $membership_level, $status ) {
$customer = rcp_get_customer_by_user_id( get_current_user_id() );
if ($customer) {
$memberships = rcp_get_memberships([
'customer_id' => $customer->get_id(),
'object_id' => $membership_level,
'status' => $status
]);
return !empty( $memberships );
} else {
return false;
}
}
@wplit
Copy link
Author

wplit commented Jul 2, 2024

Example use in Bricks.. adding the membership level, and status to check inside our function.

(here we're checking that the current user has the status of 'expired' in the membership level with the ID 2)

SCR-20240702-tcat

@wplit
Copy link
Author

wplit commented Jul 2, 2024

Remember to include the custom function name "rcp_member_status" in the https://academy.bricksbuilder.io/article/filter-bricks-code-echo_function_names/

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