Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save dwanjuki/c26d3d507f2384e3d7277bfdc8f95dfd to your computer and use it in GitHub Desktop.
Save dwanjuki/c26d3d507f2384e3d7277bfdc8f95dfd to your computer and use it in GitHub Desktop.
<?php
/**
* This recipe will check if a member has an active level associated with
* their account. It will add either 'active' or 'inactive' to QR code's data.
*
* Set your shortcode to [pmpro_membership_card qr_code='true' qr_data='other']
* for this filter to take effect.
*
* 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_membership_card_show_active( $pmpro_membership_card_user, $option ) {
// Checking if PMPro is active.
if ( ! function_exists( 'pmpro_hasMembershipLevel' ) ) {
return;
}
// Get the card user's ID.
$user_id = $pmpro_membership_card_user->ID;
if ( 'other' === $option ) {
// Change according to the levels you'd like to check for.
$has_level = pmpro_hasMembershipLevel( array( 1, 2, 3 ), $user_id );
if ( $has_level ) {
return 'active';
} else {
return 'inactive';
}
}
}
add_filter( 'pmpro_membership_card_qr_data_other', 'pmpro_membership_card_show_active', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment