Skip to content

Instantly share code, notes, and snippets.

@ronalfy
Last active April 20, 2020 11:30
Show Gist options
  • Save ronalfy/cfb1479a82a5ad120049f4d0f2f9d271 to your computer and use it in GitHub Desktop.
Save ronalfy/cfb1479a82a5ad120049f4d0f2f9d271 to your computer and use it in GitHub Desktop.
Paid Memberships Pro - Get Discount Code
<?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