Created
June 26, 2017 16:32
-
-
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
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
<?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