Skip to content

Instantly share code, notes, and snippets.

@tictag
Created July 16, 2019 06:28
Show Gist options
  • Save tictag/00cee568289f2c122ce220b4ea10e871 to your computer and use it in GitHub Desktop.
Save tictag/00cee568289f2c122ce220b4ea10e871 to your computer and use it in GitHub Desktop.
Add Gift Aid status to PMPro Member and Orders Lists and CSV Exports
// Add Gift Aid to *Members List*
// heading
function my_pmproga_memberslist_extra_cols_header() { ?>
<th><?php _e('Gift Aid', 'pmpro');?></th>
<?php }
add_action("pmpro_memberslist_extra_cols_header", "my_pmproga_memberslist_extra_cols_header");
// column
function my_pmproga_memberslist_extra_cols_body($theuser) {
?>
<td>
<?php
if( get_user_meta($theuser->ID, 'gift_aid', true) == "1" ) {
echo "Yes";
} else {
echo "No";
}
?>
</td>
<?php }
add_action("pmpro_memberslist_extra_cols_body", "my_pmproga_memberslist_extra_cols_body");
// Add Gift Aid to *Orders List*
// heading
function my_pmproga_orders_extra_cols_header($order_ids) { ?>
<th><?php _e('Gift Aid', 'pmpro');?></th>
<?php }
add_action("pmpro_orders_extra_cols_header", "my_pmproga_orders_extra_cols_header");
// column
function my_pmproga_orders_extra_cols_body($order) {
?>
<td>
<?php
if( get_user_meta($order->user_id, 'gift_aid', true) == "1" ) {
echo "Yes";
} else {
echo "No";
}
?>
</td>
<?php }
add_action("pmpro_orders_extra_cols_body", "my_pmproga_orders_extra_cols_body");
// Add Gift Aid to *Members CSV Export*
function my_pmproga_members_list_csv_extra_columns($columns)
{
$columns["gift_aid"] = "my_extra_column_gift_aid";
return $columns;
}
add_filter("pmpro_members_list_csv_extra_columns", "my_pmproga_members_list_csv_extra_columns", 10);
// These are the callback functions which take the $user object from the CSV code (which includes an array of meta data in ->metavalues, and returns the value you want.
// I expanded the code for this first function for readability, but if you have a bunch of these, you may want to scrunch them up onto one line each.
function my_extra_column_gift_aid($user)
{
if(!empty($user->metavalues->gift_aid)) {
return "Gift Aid: Yes";
} else {
return "Gift Aid: No";
}
}
// Add Gift Aid to *Orders CSV Export*
// Note Add On already adds Gift Aid to Orders CSV Export
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment