Created
May 16, 2022 09:58
-
-
Save JarrydLong/a4bcd137398ee87a0714d609c6e1be73 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 //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