Last active
April 20, 2020 11:30
-
-
Save ronalfy/cfb1479a82a5ad120049f4d0f2f9d271 to your computer and use it in GitHub Desktop.
Paid Memberships Pro - Get Discount Code
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 | |
function pmpro_custom_add_discount_code( $atts ) { | |
if ( function_exists( 'pmprosm_getCodeByUserID' ) && is_user_logged_in() ) { | |
global $current_user; | |
$code_id = pmprosm_getCodeByUserID( $current_user->ID ); // Replace $current_user->ID with sponsoree ID. | |
if ( $code_id ) { | |
$discount_code = pmprosm_getDiscountCodeByCodeID( $code_id ); | |
if ( isset( $discount_code->code ) ) { | |
return $discount_code->code; | |
} | |
} | |
} | |
return ''; | |
} | |
add_shortcode( 'pmpro_discount_code', 'pmpro_custom_add_discount_code' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment