Created
January 21, 2014 16:04
-
-
Save scottsousa/8542877 to your computer and use it in GitHub Desktop.
Paid Memberships Pro - Add discount codes to Member list
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
/** | |
* Hook into Members List header | |
*/ | |
add_action( 'pmpro_memberslist_extra_cols_header', 'my_pmpro_memberslist_extra_cols_header' ); | |
function my_pmpro_memberslist_extra_cols_header() { | |
echo '<th>Discount Code</th>'; | |
} | |
/** | |
* Hook into Members List body to show discount code | |
*/ | |
add_action( 'pmpro_memberslist_extra_cols_body', 'my_pmpro_memberslist_extra_cols_body' ); | |
function my_pmpro_memberslist_extra_cols_body( $theuser ) { | |
global $wpdb; | |
// Fetch discount code information | |
$sqlQuery = "SELECT c.id, c.code FROM $wpdb->pmpro_discount_codes_uses cu LEFT JOIN $wpdb->pmpro_discount_codes c ON cu.code_id = c.id WHERE cu.user_id = '" . $theuser->ID . "' ORDER BY c.id DESC LIMIT 1"; | |
$discount_code = $wpdb->get_row( $sqlQuery ); | |
if ( ! empty( $discount_code ) ) | |
echo '<td class="discount-code discount-code-' . $discount_code->id .'">' . $discount_code->code . '</td>'; | |
else | |
echo '<td class="discount-code"></td>'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment