Beispiel #1
0
function pmpro_cron_credit_card_expiring_warnings()
{
    global $wpdb;
    $next_month_date = date("Y-m-01", strtotime("+2 months"));
    $sqlQuery = "SELECT mu.user_id\n\t\t\t\t\t\tFROM  {$wpdb->pmpro_memberships_users} mu\n\t\t\t\t\t\t\tLEFT JOIN {$wpdb->usermeta} um1 ON mu.user_id = um1.user_id\n\t\t\t\t\t\t\t\tAND meta_key =  'pmpro_ExpirationMonth'\n\t\t\t\t\t\t\tLEFT JOIN {$wpdb->usermeta} um2 ON mu.user_id = um2.user_id\n\t\t\t\t\t\t\t\tAND um2.meta_key =  'pmpro_ExpirationYear'\n\t\t\t\t\t\t\tLEFT JOIN {$wpdb->usermeta} um3 ON mu.user_id = um3.user_id\n\t\t\t\t\t\t\t\tAND um3.meta_key = 'pmpro_credit_card_expiring_warning'\n\t\t\t\t\t\tWHERE mu.status =  'active'\n\t\t\t\t\t\t\tAND mu.cycle_number >0\n\t\t\t\t\t\t\tAND CONCAT(um2.meta_value, '-', um1.meta_value, '-01') < '" . $next_month_date . "'\n\t\t\t\t\t\t\tAND (um3.meta_value IS NULL OR CONCAT(um2.meta_value, '-', um1.meta_value, '-01') <> um3.meta_value)\n\t\t\t\t\t";
    $cc_expiring_user_ids = $wpdb->get_col($sqlQuery);
    if (!empty($cc_expiring_user_ids)) {
        require_once ABSPATH . 'wp-includes/pluggable.php';
        foreach ($cc_expiring_user_ids as $user_id) {
            //get user
            $euser = get_userdata($user_id);
            //make sure their level doesn't have a billing limit that's been reached
            $euser->membership_level = pmpro_getMembershipLevelForUser($euser->ID);
            if (!empty($euser->membership_level->billing_limit)) {
                /*
                	There is a billing limit on this level, skip for now. 
                	We should figure out how to tell if the limit has been reached
                	and if not, email the user about the expiring credit card.
                */
                continue;
            }
            //make sure they are using a credit card type billing method for their current membership level (check the last order)
            $last_order = new MemberOrder();
            $last_order->getLastMemberOrder($euser->ID);
            if (empty($last_order->accountnumber)) {
                continue;
            }
            //okay send them an email
            $send_email = apply_filters("pmpro_send_credit_card_expiring_email", true, $e->user_id);
            if ($send_email) {
                //send an email
                $pmproemail = new PMProEmail();
                $pmproemail->sendCreditCardExpiringEmail($euser);
                printf(__("Credit card expiring email sent to %s. ", "pmpro"), $euser->user_email);
            }
            //update user meta so we don't email them again
            update_user_meta($euser->ID, "pmpro_credit_card_expiring_warning", $euser->pmpro_ExpirationYear . "-" . $euser->pmpro_ExpirationMonth . "-01");
        }
    }
}