Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save JarrydLong/a4bcd137398ee87a0714d609c6e1be73 to your computer and use it in GitHub Desktop.
Save JarrydLong/a4bcd137398ee87a0714d609c6e1be73 to your computer and use it in GitHub Desktop.
<?php //do not copy
/**
* This recipe will display the earnings value of an affiliate via shortcode.
* Add [affiliate_earnings] to a page to display the current users earnings.
*
* The default roles that we're looking for are subscribers. You can change this on line 18
* The number of days a cookie will remain active before expiring is 30 days (Line 49)
*
* Add this code to your PMPro Customizations Plugin - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
* Works for PayPal Express and Stripe payment gateways.
* www.paidmembershipspro.com
*/
function mypmpro_show_earnings() {
global $wpdb, $current_user;
$username = $current_user->user_nicename;
$sql = "SELECT id FROM $wpdb->pmpro_affiliates WHERE `affiliateuser` = '$username' LIMIT 1 ";
$result = $wpdb->get_var( $sql );
$earnings = $wpdb->get_var("SELECT SUM(total) FROM $wpdb->pmpro_membership_orders WHERE affiliate_id = '" . esc_sql($result) . "' AND status NOT IN('pending', 'error', 'refunded', 'refund', 'token', 'review')");
return pmpro_formatPrice($earnings);
}
add_shortcode( 'affiliate_earnings', 'mypmpro_show_earnings' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment