Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save JarrydLong/561f00fb05a7b09210fd75b89e593f54 to your computer and use it in GitHub Desktop.
Save JarrydLong/561f00fb05a7b09210fd75b89e593f54 to your computer and use it in GitHub Desktop.
<?php //do not copy
/**
* This recipe will add a 'Commission' column to the Affiliate, Report and CSV Export tables
*
* Note, change the value of $pmpro_affiliate_rate to your preferred commission rate.
*
* You can add this recipe to your site by creating a custom plugin
* or using the Code Snippets plugin available for free in the WordPress repository.
* Read this companion article for step-by-step directions on either method.
* https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
global $pmpro_affiliate_rate;
$pmpro_affiliate_rate = '0.15'; // Indicates 15%
/**
* Adds the Comission header to the reports page
*/
function mypmpro_affiliate_commission_header() {
echo "<th>Commission</th>";
}
add_action( 'pmpro_affiliate_report_extra_cols_header', 'mypmpro_affiliate_commission_header' );
//Adds the header to the affiliate page
add_action( 'pmpro_affiliate_extra_cols_header', 'mypmpro_affiliate_commission_header' );
/**
* Adds the contents of the commission to each report row
*/
function mypmpro_affiliate_report_commission_row( $order ) {
global $pmpro_affiliate_rate, $pmpro_currency_symbol;
$order_total = $order->total;
$commission = (float)$order_total * (float)$pmpro_affiliate_rate;
echo "<td>".pmpro_formatPrice( $commission )."</td>";
}
add_action( 'pmpro_affiliate_report_extra_cols_body', 'mypmpro_affiliate_report_commission_row', 10, 1 );
/**
* Adds the contents of the commission to each affiliate row
*/
function mypmpro_affiliate_commission_row( $affiliate, $earnings ) {
global $pmpro_affiliate_rate, $pmpro_currency_symbol;
$commission = (float)$earnings * (float)$pmpro_affiliate_rate;
echo "<td>".pmpro_formatPrice( $commission )."</td>";
}
add_action( 'pmpro_affiliate_extra_cols_body', 'mypmpro_affiliate_commission_row', 10, 2 );
/**
* Adds to the CSV export columns
*/
function mypmpro_affiliate_commission_header_export( $headings ) {
$headings[] = 'commission';
return $headings; //Adds the commision heading to the export
}
add_filter( 'pmpro_affiliate_list_csv_extra_columns', 'mypmpro_affiliate_commission_header_export', 10, 1 );
/**
* Adds the commission to the export data
*/
function mypmpro_affiliate_commission_row_export( $row, $order ) {
global $pmpro_affiliate_rate, $pmpro_currency_symbol;
$order_total = $order->total;
$commission = (float)$order_total * (float)$pmpro_affiliate_rate;
$row[] = $commission;
return $row;
}
add_filter( 'pmpro_affiliate_list_csv_extra_column_data', 'mypmpro_affiliate_commission_row_export', 10, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment