Created
October 9, 2020 10:59
-
-
Save andrewlimaza/be0c5abe8e927b0a9a68472882e30b50 to your computer and use it in GitHub Desktop.
Integrate Membership Card with Invite Only Member Add On [Paid Memberships Pro]
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 | |
/** | |
* Set the QR code to link to a checkout with an invite code when someone scans a Q. | |
* Add this code to your site by following this guide - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/ | |
*/ | |
function my_pmpro_membership_card_qr_invite_code( $card_user, $option ) { | |
global $pmproio_invite_required_levels; | |
if ( $option == 'other' ) { | |
$codes = get_user_meta($card_user->ID, 'pmpro_invite_code', true); | |
if ( ! $codes ) { | |
return ''; //Change this to return default value for members that don't have invite codes. | |
} | |
$code = ''; | |
if ( is_array( $codes ) ) { | |
$code = $codes[0]; | |
} else { | |
$code = $codes; | |
} | |
// Default checkout ID if no required_levels is found. | |
$checkout_id = 1; | |
if ( is_array( $pmproio_invite_required_levels ) && ! empty( $pmproio_invite_required_levels[0]) ) { | |
$checkout_id = $pmproio_invite_required_levels[0]; | |
} | |
return pmpro_url( 'checkout', '?level=' . $checkout_id . '&invite_code=' . $code, "https" ); | |
} | |
} | |
add_filter( 'pmpro_membership_card_qr_data_other', 'my_pmpro_membership_card_qr_invite_code', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment