Skip to content

Instantly share code, notes, and snippets.

@dparker1005
Created June 26, 2017 16:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dparker1005/e241880a24c1fa295232bb430e8f4d38 to your computer and use it in GitHub Desktop.
Save dparker1005/e241880a24c1fa295232bb430e8f4d38 to your computer and use it in GitHub Desktop.
Adds the discount code ID and Name to the Members List page of Paid Memberships Pro
<?php
//To add Discount Code Information to Members List
//Add Discount Code Information Column to Members List Header
function my_pmpro_memberslist_extra_cols_header($theusers)
{
?>
<th><?php _e('Discount ID', 'pmpro');?></th>
<th><?php _e('Discount Code', 'pmpro');?></th>
<?php
}
add_action('pmpro_memberslist_extra_cols_header', 'my_pmpro_memberslist_extra_cols_header');
//Add Discount Code Information to Members List Rows
function my_pmpro_memberslist_extra_cols_body($theuser){
if(!empty($theuser->data->ID)){
//grab discount code info
global $wpdb;
$disSql = $wpdb->prepare("
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 = %d
ORDER BY c.id DESC
LIMIT 1",
$theuser->ID
);
$discount_code = $wpdb->get_row($disSql);
if (empty($discount_code)){
echo "<td>None</td><td>None</td>";
}
else{
echo "<td>".$discount_code->id."</td><td>".$discount_code->code."</td>";
}
}
}
add_action('pmpro_memberslist_extra_cols_body', 'my_pmpro_memberslist_extra_cols_body');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment