Last active
July 31, 2018 17:40
-
-
Save greathmaster/ebbafa61f3a6e2309320667b20f4577c to your computer and use it in GitHub Desktop.
Add the Donation amount to the Members List CSV Export
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 | |
function my_pmpro_members_list_csv_extra_columns($columns) | |
{ | |
$columns["donation"] = "my_extra_column_donation"; | |
return $columns; | |
} | |
add_filter("pmpro_members_list_csv_extra_columns", "my_pmpro_members_list_csv_extra_columns", 10); | |
function my_extra_column_donation($user) | |
{ | |
$order_id = getFirstMemberOrder($user->ID); | |
$order = new MemberOrder(); | |
$order->getMemberOrderByID($order_id); | |
if(!empty($order)) | |
{ | |
$donation = pmprodon_getPriceComponents($order)['donation']; | |
return $donation; | |
} | |
else | |
{ | |
return ""; | |
} | |
} | |
function getFirstMemberOrder($user_id = NULL, $status = 'success', $membership_id = NULL, $gateway = NULL, $gateway_environment = NULL) | |
{ | |
global $current_user, $wpdb; | |
if(!$user_id) | |
$user_id = $current_user->ID; | |
if(!$user_id) | |
return false; | |
//build query | |
$sqlQuery = "SELECT id FROM $wpdb->pmpro_membership_orders WHERE user_id = '" . $user_id . "' "; | |
if(!empty($status) && is_array($status)) | |
$sqlQuery .= "AND status IN('" . implode("','", $status) . "') "; | |
elseif(!empty($status)) | |
$sqlQuery .= "AND status = '" . esc_sql($status) . "' "; | |
if(!empty($membership_id)) | |
$sqlQuery .= "AND membership_id = '" . $membership_id . "' "; | |
if(!empty($gateway)) | |
$sqlQuery .= "AND gateway = '" . esc_sql($gateway) . "' "; | |
if(!empty($gateway_environment)) | |
$sqlQuery .= "AND gateway_environment = '" . esc_sql($gateway_environment) . "' "; | |
$sqlQuery .= "ORDER BY timestamp ASC LIMIT 1"; | |
//get id | |
$id = $wpdb->get_var($sqlQuery); | |
return $id; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment