Skip to content

Instantly share code, notes, and snippets.

@scottsousa
Created January 21, 2014 16:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scottsousa/8542877 to your computer and use it in GitHub Desktop.
Save scottsousa/8542877 to your computer and use it in GitHub Desktop.
Paid Memberships Pro - Add discount codes to Member list
/**
* 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