Last active
May 20, 2021 03:27
-
-
Save andrewlimaza/c28d9246829789d86d87fe98939d1d15 to your computer and use it in GitHub Desktop.
Sponsored members checkout URL when scanning QR code [Paid Memberships Pro]
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 | |
/** | |
* If a user is a parent/sponsor member, set the QR code to the child checkout URL. | |
* This will get the first sponsored level checkout URL and discount code. | |
* Only set the QR code to the checkout URL if there are available seats. | |
* Add this code to your site by visiting - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/ | |
*/ | |
function my_pmpro_membership_card_sponsored_members( $card_user, $option ) { | |
// If the option isn't other, let's not run the code further down. | |
if ( $option != 'other' ) { | |
return $card_user->ID; | |
} | |
// Check if Sponsored Members is activated. | |
if ( ! function_exists( 'pmprosm_isMainLevel' ) ) { | |
return $card_user->ID; | |
} | |
// Check to make sure they have a level ID | |
if ( empty( $card_user->membership_level->ID ) ) { | |
return $card_user->ID; | |
} | |
// Check to see if the user has a "parent" level. | |
if ( ! pmprosm_isMainLevel( $card_user->membership_level->ID ) ) { | |
return $card_user->ID; | |
} | |
$user_level_id = $card_user->membership_level->ID; | |
$code_id = pmprosm_getCodeByUserID( $card_user->ID ); | |
// Check if the user has a discount code (parent) and figure out the checkout URL for sponsored members. | |
if ( ! empty( $code_id ) ) { | |
$discount_code = pmprosm_getDiscountCodeByCodeID( $code_id ); | |
$uses = intval( $discount_code->uses ); | |
$children = count( pmprosm_getChildren( $card_user->ID ) ); | |
$checkout_data = pmprosm_get_checkout_urls( $discount_code ); | |
$checkout_url = $checkout_data[0]['url']; //Only get the first checkout level. | |
} | |
// Only show the checkout URL if uses are available and not used up. | |
if ( ! empty( $checkout_url ) && $children < $uses ) { | |
return $checkout_url; | |
} else { | |
return $card_user->ID; | |
} | |
return $card_user->ID; | |
} | |
add_filter( 'pmpro_membership_card_qr_data_other', 'my_pmpro_membership_card_sponsored_members', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment