本文整理汇总了PHP中pmpro_changeMembershipLevel函数的典型用法代码示例。如果您正苦于以下问题:PHP pmpro_changeMembershipLevel函数的具体用法?PHP pmpro_changeMembershipLevel怎么用?PHP pmpro_changeMembershipLevel使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pmpro_changeMembershipLevel函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: pmpro_cron_expire_memberships
function pmpro_cron_expire_memberships()
{
global $wpdb;
//make sure we only run once a day
$today = date("Y-m-d", current_time("timestamp"));
//look for memberships that expired before today
$sqlQuery = "SELECT mu.user_id, mu.membership_id, mu.startdate, mu.enddate FROM {$wpdb->pmpro_memberships_users} mu WHERE mu.status = 'active' AND mu.enddate IS NOT NULL AND mu.enddate <> '' AND mu.enddate <> '0000-00-00 00:00:00' AND DATE(mu.enddate) <= '" . $today . "' ORDER BY mu.enddate";
if (defined('PMPRO_CRON_LIMIT')) {
$sqlQuery .= " LIMIT " . PMPRO_CRON_LIMIT;
}
$expired = $wpdb->get_results($sqlQuery);
foreach ($expired as $e) {
do_action("pmpro_membership_pre_membership_expiry", $e->user_id, $e->membership_id);
//remove their membership
pmpro_changeMembershipLevel(false, $e->user_id, 'expired');
do_action("pmpro_membership_post_membership_expiry", $e->user_id, $e->membership_id);
$send_email = apply_filters("pmpro_send_expiration_email", true, $e->user_id);
if ($send_email) {
//send an email
$pmproemail = new PMProEmail();
$euser = get_userdata($e->user_id);
$pmproemail->sendMembershipExpiredEmail($euser);
if (current_user_can('manage_options')) {
printf(__("Membership expired email sent to %s. ", "pmpro"), $euser->user_email);
} else {
echo ". ";
}
}
}
}
示例2: pmpro_cron_expire_memberships
function pmpro_cron_expire_memberships()
{
global $wpdb;
//make sure we only run once a day
$today = date("Y-m-d");
//look for memberships that expired before today
$sqlQuery = "SELECT mu.user_id, mu.membership_id, mu.startdate, mu.enddate FROM $wpdb->pmpro_memberships_users mu WHERE mu.status = 'active' AND mu.enddate IS NOT NULL AND mu.enddate <> '' AND mu.enddate <> '0000-00-00 00:00:00' AND DATE(mu.enddate) <= '" . $today . "' ORDER BY mu.enddate";
$expired = $wpdb->get_results($sqlQuery);
foreach($expired as $e)
{
//remove their membership
pmpro_changeMembershipLevel(false, $e->user_id);
$send_email = apply_filters("pmpro_send_expiration_email", true, $e->user_id);
if($send_email)
{
//send an email
$pmproemail = new PMProEmail();
$euser = get_userdata($e->user_id);
$pmproemail->sendMembershipExpiredEmail($euser);
echo "Membership expired email sent to " . $euser->user_email . ". ";
}
}
}
示例3: pmpro_delete_user
function pmpro_delete_user($user_id = NULL)
{
global $wpdb;
//changing their membership level to 0 will cancel any subscription and remove their membership level entry
//we don't remove the orders because it would affect reporting
if (pmpro_changeMembershipLevel(0, $user_id)) {
//okay
} else {
//okay, guessing they didn't have a level
}
}
示例4: pmprosl_pmpro_default_registration_level
function pmprosl_pmpro_default_registration_level($user_id)
{
global $pmpro_level;
//if default is set and we're not otherwise checking out
$default_level = get_option('pmpro_social_login_default_level');
if (!empty($default_level) && empty($pmpro_level) && empty($_REQUEST['level'])) {
pmpro_changeMembershipLevel($default_level, $user_id);
$user = get_userdata($user_id);
$user->membership_level = pmpro_getMembershipLevelForUser($user->ID);
//send email to member
$pmproemail = new PMProEmail();
$pmproemail->sendCheckoutEmail($user, false);
//send email to admin
$pmproemail = new PMProEmail();
$pmproemail->sendCheckoutAdminEmail($user, false);
}
}
示例5: pmpro_delete_user
function pmpro_delete_user($user_id = NULL)
{
global $wpdb;
//changing their membership level to 0 will cancel any subscription and remove their membership level entry
//we don't remove the orders because it would affect reporting
if (pmpro_changeMembershipLevel(0, $user_id)) {
//okay
} else {
//couldn't delete the subscription
//we should probably notify the admin
global $pmpro_error;
if (!empty($pmpro_error)) {
$pmproemail = new PMProEmail();
$pmproemail->data = array("body" => "<p>" . sprintf(__("There was an error canceling the subscription for user with ID=%s. You will want to check your payment gateway to see if their subscription is still active.", "pmpro"), strval($user_id)) . "</p><p>Error: " . $pmpro_error . "</p>");
$last_order = $wpdb->get_row("SELECT * FROM {$wpdb->pmpro_membership_orders} WHERE user_id = '" . $user_id . "' ORDER BY timestamp DESC LIMIT 1");
if (!empty($last_order)) {
$pmproemail->data["body"] .= "<p>Last Invoice:<br />" . nl2br(var_export($last_order, true)) . "</p>";
}
$pmproemail->sendEmail(get_bloginfo("admin_email"));
}
}
}
示例6: pmpro_membership_level_profile_fields_update
function pmpro_membership_level_profile_fields_update()
{
//get the user id
global $wpdb, $current_user, $user_ID;
get_currentuserinfo();
if (!empty($_REQUEST['user_id'])) {
$user_ID = $_REQUEST['user_id'];
}
$membership_level_capability = apply_filters("pmpro_edit_member_capability", "manage_options");
if (!current_user_can($membership_level_capability)) {
return false;
}
//level change
if (isset($_REQUEST['membership_level'])) {
//if the level is being set to 0 by the admin, it's a cancellation.
$changed_or_cancelled = '';
if ($_REQUEST['membership_level'] === 0 || $_REQUEST['membership_level'] === '0' || $_REQUEST['membership_level'] == '') {
$changed_or_cancelled = 'admin_cancelled';
} else {
$changed_or_cancelled = 'admin_changed';
}
//if the cancel at gateway box is not checked, don't cancel
if (empty($_REQUEST['cancel_subscription'])) {
add_filter('pmpro_cancel_previous_subscriptions', 'pmpro_cancel_previous_subscriptions_false');
}
//do the change
if (pmpro_changeMembershipLevel($_REQUEST['membership_level'], $user_ID, $changed_or_cancelled)) {
//it changed. send email
$level_changed = true;
}
//remove filter after ward
if (empty($_REQUEST['cancel_subscription'])) {
remove_filter('pmpro_cancel_previous_subscriptions', 'pmpro_cancel_previous_subscriptions_false');
}
}
//expiration change
if (!empty($_REQUEST['expires'])) {
//update the expiration date
$expiration_date = intval($_REQUEST['expires_year']) . "-" . str_pad(intval($_REQUEST['expires_month']), 2, "0", STR_PAD_LEFT) . "-" . str_pad(intval($_REQUEST['expires_day']), 2, "0", STR_PAD_LEFT);
$sqlQuery = "UPDATE {$wpdb->pmpro_memberships_users} SET enddate = '" . $expiration_date . "' WHERE status = 'active' AND membership_id = '" . intval($_REQUEST['membership_level']) . "' AND user_id = '" . $user_ID . "' LIMIT 1";
if ($wpdb->query($sqlQuery)) {
$expiration_changed = true;
}
} elseif (isset($_REQUEST['expires'])) {
//already blank? have to check for null or '0000-00-00 00:00:00' or '' here.
$sqlQuery = "SELECT user_id FROM {$wpdb->pmpro_memberships_users} WHERE (enddate IS NULL OR enddate = '' OR enddate = '0000-00-00 00:00:00') AND status = 'active' AND user_id = '" . $user_ID . "' LIMIT 1";
$blank = $wpdb->get_var($sqlQuery);
if (empty($blank)) {
//null out the expiration
$sqlQuery = "UPDATE {$wpdb->pmpro_memberships_users} SET enddate = NULL WHERE status = 'active' AND membership_id = '" . intval($_REQUEST['membership_level']) . "' AND user_id = '" . $user_ID . "' LIMIT 1";
if ($wpdb->query($sqlQuery)) {
$expiration_changed = true;
}
}
}
//emails if there was a change
if (!empty($level_changed) || !empty($expiration_changed)) {
//email to admin
$pmproemail = new PMProEmail();
if (!empty($expiration_changed)) {
$pmproemail->expiration_changed = true;
}
$pmproemail->sendAdminChangeAdminEmail(get_userdata($user_ID));
//send email
if (!empty($_REQUEST['send_admin_change_email'])) {
//email to member
$pmproemail = new PMProEmail();
if (!empty($expiration_changed)) {
$pmproemail->expiration_changed = true;
}
$pmproemail->sendAdminChangeEmail(get_userdata($user_ID));
}
}
}
示例7: check_benefactor_status
function check_benefactor_status($email)
{
if (!$email) {
$user = wp_get_current_user();
} else {
$user = get_user_by_email($email);
}
$membership = pmpro_getMembershipLevelForUser($user->ID);
if (!$membership->ID) {
return;
}
$invoices = getInvoicesRecurring($user);
if (!empty($invoices)) {
$gateway = new PMProGateway_paypalexpress();
$lastOrderInfo = $gateway->getSubscriptionStatus($invoices[0]);
if ($lastOrderInfo['STATUS'] == 'Cancelled') {
// neu cancel tu paypal => cancel benefactor
pmpro_changeMembershipLevel(0, $user->ID, $current_user->membership_level->ID, false);
}
} else {
pmpro_changeMembershipLevel(0, $user->ID, $current_user->membership_level->ID, false);
}
return;
}
示例8: pmprowoo_cancelled_subscription
function pmprowoo_cancelled_subscription($user_id, $subscription_key)
{
global $pmprowoo_product_levels;
//don't bother if array is empty
if (empty($pmprowoo_product_levels)) {
return;
}
/*
does this order contain a membership product?
*/
$subscription = WC_Subscriptions_Manager::get_users_subscription($user_id, $subscription_key);
if (isset($subscription['product_id']) && isset($subscription['order_id'])) {
$product_id = $subscription['product_id'];
$order_id = $subscription['order_id'];
//membership product ids
$product_ids = array_keys($pmprowoo_product_levels);
//get order
$order = new WC_Order($order_id);
//does the order have a user id and some products?
if (!empty($order->customer_user) && !empty($product_id)) {
//is there a membership level for this product?
if (in_array($product_id, $product_ids)) {
//add the user to the level
pmpro_changeMembershipLevel(0, $order->customer_user);
}
}
}
}
示例9: pmpro_insChangeMembershipLevel
function pmpro_insChangeMembershipLevel($txn_id, &$morder)
{
$recurring = pmpro_getParam('rectoken', 'POST');
//filter for level
$morder->membership_level = apply_filters("pmpro_inshandler_level", $morder->membership_level, $morder->user_id);
//set the start date to current_time('mysql') but allow filters (documented in preheaders/checkout.php)
$startdate = apply_filters("pmpro_checkout_start_date", "'" . current_time('mysql') . "'", $morder->user_id, $morder->membership_level);
//fix expiration date
if (!empty($morder->membership_level->expiration_number)) {
$enddate = "'" . date("Y-m-d", strtotime("+ " . $morder->membership_level->expiration_number . " " . $morder->membership_level->expiration_period, current_time("timestamp"))) . "'";
} else {
$enddate = "NULL";
}
//filter the enddate (documented in preheaders/checkout.php)
$enddate = apply_filters("pmpro_checkout_end_date", $enddate, $morder->user_id, $morder->membership_level, $startdate);
//get discount code
$morder->getDiscountCode();
if (!empty($morder->discount_code)) {
//update membership level
$morder->getMembershipLevel(true);
$discount_code_id = $morder->discount_code->id;
} else {
$discount_code_id = "";
}
//custom level to change user to
$custom_level = array('user_id' => $morder->user_id, 'membership_id' => $morder->membership_level->id, 'code_id' => $discount_code_id, 'initial_payment' => $morder->membership_level->initial_payment, 'billing_amount' => $morder->membership_level->billing_amount, 'cycle_number' => $morder->membership_level->cycle_number, 'cycle_period' => $morder->membership_level->cycle_period, 'billing_limit' => $morder->membership_level->billing_limit, 'trial_amount' => $morder->membership_level->trial_amount, 'trial_limit' => $morder->membership_level->trial_limit, 'startdate' => $startdate, 'enddate' => $enddate);
global $pmpro_error;
if (!empty($pmpro_error)) {
//echo $pmpro_error;
fnlog($pmpro_error);
}
if (pmpro_changeMembershipLevel($custom_level, $morder->user_id) !== false) {
//update order status and transaction ids
$morder->status = "success";
$morder->payment_transaction_id = $txn_id;
if (!$recurring) {
$morder->subscription_transaction_id = $txn_id;
} else {
$morder->subscription_transaction_id = '';
}
$morder->saveOrder();
//add discount code use
if (!empty($discount_code) && !empty($use_discount_code)) {
$wpdb->query("INSERT INTO {$wpdb->pmpro_discount_codes_uses} (code_id, user_id, order_id, timestamp) VALUES('" . $discount_code_id . "', '" . $morder->user_id . "', '" . $morder->id . "', '" . current_time('mysql') . "')");
}
//hook
do_action("pmpro_after_checkout", $morder->user_id);
//print_r ($morder); die;
//setup some values for the emails
if (!empty($morder)) {
$invoice = new MemberOrder($morder->id);
} else {
$invoice = NULL;
}
fnlog("CHANGEMEMBERSHIPLEVEL: ORDER: " . var_export($morder, true) . "\n---\n");
$user = get_userdata($morder->user_id);
if (empty($user)) {
return false;
}
$user->membership_level = $morder->membership_level;
//make sure they have the right level info
//send email to member
$pmproemail = new PMProEmail();
$pmproemail->sendCheckoutEmail($user, $invoice);
//send email to admin
$pmproemail = new PMProEmail();
$pmproemail->sendCheckoutAdminEmail($user, $invoice);
return true;
} else {
return false;
}
}
示例10: do_action
}
do_action("pmpro_save_membership_level", $saveid);
} elseif ($action == "delete_membership_level") {
global $wpdb;
$ml_id = $_REQUEST['deleteid'];
if ($ml_id > 0) {
do_action("pmpro_delete_membership_level", $ml_id);
//remove any categories from the ml
$sqlQuery = "DELETE FROM {$wpdb->pmpro_memberships_categories} WHERE membership_id = '{$ml_id}'";
$r1 = $wpdb->query($sqlQuery);
//cancel any subscriptions to the ml
$r2 = true;
$user_ids = $wpdb->get_col("SELECT user_id FROM {$wpdb->pmpro_memberships_users} WHERE membership_id = '{$ml_id}' AND status = 'active'");
foreach ($user_ids as $user_id) {
//change there membership level to none. that will handle the cancel
if (pmpro_changeMembershipLevel(0, $user_id)) {
//okay
} else {
//couldn't delete the subscription
//we should probably notify the admin
$pmproemail = new PMProEmail();
$pmproemail->data = array("body" => "<p>" . sprintf(__("There was an error canceling the subscription for user with ID=%d. You will want to check your payment gateway to see if their subscription is still active.", "pmpro"), $user_id) . "</p>");
$last_order = $wpdb->get_row("SELECT * FROM {$wpdb->pmpro_membership_orders} WHERE user_id = '" . $user_id . "' ORDER BY timestamp DESC LIMIT 1");
if ($last_order) {
$pmproemail->data["body"] .= "<p>" . __("Last Invoice", "pmpro") . ":<br />" . nl2br(var_export($last_order, true)) . "</p>";
}
$pmproemail->sendEmail(get_bloginfo("admin_email"));
$r2 = false;
}
}
//delete the ml
示例11: update_user_meta
} else {
//other user meta
update_user_meta($user_id, "user_notes", $user_notes);
//figure out start date
$now = current_time('timestamp');
$startdate = date("Y-m-d", $now);
//figure out end date
if (!empty($_REQUEST['expires'])) {
//update the expiration date
$enddate = intval($_REQUEST['expires_year']) . "-" . str_pad(intval($_REQUEST['expires_month']), 2, "0", STR_PAD_LEFT) . "-" . str_pad(intval($_REQUEST['expires_day']), 2, "0", STR_PAD_LEFT);
} else {
$enddate = '';
}
//add membership level
$custom_level = array('user_id' => $user_id, 'membership_id' => $membership_level, 'code_id' => '', 'initial_payment' => $total, 'billing_amount' => '', 'cycle_number' => '', 'cycle_period' => '', 'billing_limit' => '', 'trial_amount' => '', 'trial_limit' => '', 'startdate' => $startdate, 'enddate' => $enddate);
pmpro_changeMembershipLevel($custom_level, $user_id);
//add order
//blank order for free levels
if (empty($morder)) {
$morder = new MemberOrder();
$morder->InitialPayment = $total;
$morder->Email = $user_email;
$morder->gateway = $gateway;
$morder->status = "success";
}
//add an item to the history table, cancel old subscriptions
if (!empty($morder)) {
$morder->user_id = $user_id;
$morder->membership_id = $membership_level;
$morder->notes = $order_notes;
$morder->saveOrder();
示例12: pmpro_insRecurringRestarted
function pmpro_insRecurringRestarted($morder)
{
global $pmpro_error;
//hook to do other stuff when payments restart
do_action("pmpro_subscription_recuring_restarted", $last_order);
$worked = pmpro_changeMembershipLevel($morder->membership_level->id, $morder->user->ID);
if ($worked === true) {
//$pmpro_msg = __("Your membership has been cancelled.", 'pmpro');
//$pmpro_msgt = "pmpro_success";
//send an email to the member
$pmproemail = new PMProEmail();
$pmproemail->sendCheckoutEmail($morder->user, $morder);
//send email to admin
$pmproemail = new PMProEmail();
$pmproemail->sendCheckoutAdminEmail($morder->user, $morder);
inslog("Subscription restarted due to 'recurring restarted' INS notification.");
return true;
} else {
return false;
}
}
示例13: pmpro_payflow_recurring_orders
//.........这里部分代码省略.........
continue;
}
//check subscription
if (!empty($last_order->subscription_transaction_id)) {
echo "- Checking subscription #" . $last_order->subscription_transaction_id . ".<br />";
$status = pmpropfro_getSubscriptionPayments($last_order);
//find orders
$payments = pmpropfro_processPaymentHistory($status);
if (!empty($payments)) {
foreach ($payments as $payment) {
if ($payment['P_TRANSTATE'] == 1 || $payment['P_TRANSTATE'] == 11) {
echo "- Failed payment #" . $payment['P_PNREF'] . ".";
//check if we have this one already
$old_order = new MemberOrder();
$old_order->getMemberOrderByPaymentTransactionID($payment['P_PNREF']);
if (empty($old_order->id)) {
$failed_payment_emails[] = $user->user_email;
//not there yet, add it
$morder = new MemberOrder();
$morder->user_id = $last_order->user_id;
$morder->membership_id = $last_order->membership_id;
$morder->payment_transaction_id = $payment['P_PNREF'];
$morder->subscription_transaction_id = $last_order->subscription_transaction_id;
$morder->InitialPayment = $payment['P_AMT'];
//not the initial payment, but the class is expecting that
$morder->PaymentAmount = $payment['P_AMT'];
$morder->status = "error";
//save
$morder->saveOrder();
$morder->getMemberOrderByID($morder->id);
echo " Saving order.";
//this will affect the main query, so need to roll back the "end" 1 space
$end--;
//unless there is another non-failed payment more recent, cancel their membership
if (!pmpropfro_paymentAfter($payments, strtotime($payment['P_TRANSTIME']))) {
//cancel membership
pmpro_changeMembershipLevel(0, $user_id);
echo " Membership cancelled. Member emailed.";
//notify them
$myemail = new PMProEmail();
$myemail->sendCancelEmail($user);
} else {
echo " More recent successful order. So not cancelling membership.";
}
} else {
echo " Already logged.";
}
echo "<br />";
} elseif ($payment['P_TRANSTATE'] == 8) {
//check if we have this one already
$old_order = new MemberOrder();
$old_order->getMemberOrderByPaymentTransactionID($payment['P_PNREF']);
if (empty($old_order->id)) {
//not there yet, add it
$morder = new MemberOrder();
$morder->user_id = $last_order->user_id;
$morder->membership_id = $last_order->membership_id;
$morder->payment_transaction_id = $payment['P_PNREF'];
$morder->subscription_transaction_id = $last_order->subscription_transaction_id;
$morder->InitialPayment = $payment['P_AMT'];
//not the initial payment, but the class is expecting that
$morder->PaymentAmount = $payment['P_AMT'];
$morder->status = "success";
//save
$morder->saveOrder();
$morder->getMemberOrderByID($morder->id);
//this will affect the main query, so need to roll back the "end" 1 space
$end--;
if (!empty($morder->id)) {
//update the timestamp
$timestamp = date("Y-m-d H:i:s", strtotime($payment['P_TRANSTIME']));
$wpdb->query("UPDATE {$wpdb->pmpro_membership_orders} SET timestamp = '" . $timestamp . "' WHERE id = '" . $morder->id . "' LIMIT 1");
echo "<strong>- Order added. #" . $morder->id . ".</strong><br />";
//email the user their invoice
$pmproemail = new PMProEmail();
$pmproemail->sendInvoiceEmail($user, $morder);
echo "- Invoice email sent to " . $user->user_email . ".";
} else {
echo "- Error adding order.";
}
} else {
echo "- Order already saved for #" . $payment['P_TRANSTATE'] . ".<br />";
}
} else {
echo "<strong>- Payment " . $payment['P_PNREF'] . " has status #" . $payment['P_TRANSTATE'] . " so not saving.</strong><br />";
}
}
} else {
echo "- No payments found.<br />";
}
}
echo "<hr />";
echo "Going to start with #" . $end . " next time.";
update_option('payflow_recurring_orders_cron_count', $end);
}
echo "<hr />";
foreach ($failed_payment_emails as $email) {
echo $email . "<br />";
}
}
示例14: pmpro_ipnChangeMembershipLevel
function pmpro_ipnChangeMembershipLevel($txn_id, &$morder)
{
//filter for level
$morder->membership_level = apply_filters("pmpro_ipnhandler_level", $morder->membership_level, $morder->user_id);
//fix expiration date
if (!empty($morder->membership_level->expiration_number)) {
$enddate = "'" . date("Y-m-d", strtotime("+ " . $morder->membership_level->expiration_number . " " . $morder->membership_level->expiration_period, current_time("timestamp"))) . "'";
} else {
$enddate = "NULL";
}
//get discount code
$morder->getDiscountCode();
if (!empty($morder->discount_code)) {
//update membership level
$morder->getMembershipLevel(true);
$discount_code_id = $morder->discount_code->id;
} else {
$discount_code_id = "";
}
//set the start date to current_time('timestamp') but allow filters
$startdate = apply_filters("pmpro_checkout_start_date", "'" . current_time('mysql') . "'", $morder->user_id, $morder->membership_level);
//custom level to change user to
$custom_level = array('user_id' => $morder->user_id, 'membership_id' => $morder->membership_level->id, 'code_id' => $discount_code_id, 'initial_payment' => $morder->membership_level->initial_payment, 'billing_amount' => $morder->membership_level->billing_amount, 'cycle_number' => $morder->membership_level->cycle_number, 'cycle_period' => $morder->membership_level->cycle_period, 'billing_limit' => $morder->membership_level->billing_limit, 'trial_amount' => $morder->membership_level->trial_amount, 'trial_limit' => $morder->membership_level->trial_limit, 'startdate' => $startdate, 'enddate' => $enddate);
global $pmpro_error;
if (!empty($pmpro_error)) {
echo $pmpro_error;
ipnlog($pmpro_error);
}
//change level and continue "checkout"
if (pmpro_changeMembershipLevel($custom_level, $morder->user_id) !== false) {
//update order status and transaction ids
$morder->status = "success";
$morder->payment_transaction_id = $txn_id;
if (!empty($_POST['subscr_id'])) {
$morder->subscription_transaction_id = $_POST['subscr_id'];
} else {
$morder->subscription_transaction_id = "";
}
$morder->saveOrder();
//add discount code use
if (!empty($discount_code) && !empty($use_discount_code)) {
$wpdb->query("INSERT INTO {$wpdb->pmpro_discount_codes_uses} (code_id, user_id, order_id, timestamp) VALUES('" . $discount_code_id . "', '" . $morder->user_id . "', '" . $morder->id . "', '" . current_time('mysql') . "");
}
//save first and last name fields
if (!empty($_POST['first_name'])) {
$old_firstname = get_user_meta($morder->user_id, "first_name", true);
if (empty($old_firstname)) {
update_user_meta($morder->user_id, "first_name", $_POST['first_name']);
}
}
if (!empty($_POST['last_name'])) {
$old_lastname = get_user_meta($morder->user_id, "last_name", true);
if (empty($old_lastname)) {
update_user_meta($morder->user_id, "last_name", $_POST['last_name']);
}
}
//hook
do_action("pmpro_after_checkout", $morder->user_id);
//setup some values for the emails
if (!empty($morder)) {
$invoice = new MemberOrder($morder->id);
} else {
$invoice = NULL;
}
$user = get_userdata($morder->user_id);
$user->membership_level = $morder->membership_level;
//make sure they have the right level info
//send email to member
$pmproemail = new PMProEmail();
$pmproemail->sendCheckoutEmail($user, $invoice);
//send email to admin
$pmproemail = new PMProEmail();
$pmproemail->sendCheckoutAdminEmail($user, $invoice);
return true;
} else {
return false;
}
}
示例15: pmpro_ipnChangeMembershipLevel
function pmpro_ipnChangeMembershipLevel($txn_id, &$morder)
{
//filter for level
$morder->membership_level = apply_filters("pmpro_ipnhandler_level", $morder->membership_level, $morder->user_id);
//fix expiration date
if(!empty($morder->membership_level->expiration_number))
{
$enddate = "'" . date("Y-m-d", strtotime("+ " . $morder->membership_level->expiration_number . " " . $morder->membership_level->expiration_period)) . "'";
}
else
{
$enddate = "NULL";
}
//get discount code (NOTE: but discount_code isn't set here. How to handle discount codes for PayPal Standard?)
$use_discount_code = true; //assume yes
if(!empty($discount_code) && !empty($use_discount_code))
$discount_code_id = $wpdb->get_var("SELECT id FROM $wpdb->pmpro_discount_codes WHERE code = '" . $discount_code . "' LIMIT 1");
else
$discount_code_id = "";
//set the start date to NOW() but allow filters
$startdate = apply_filters("pmpro_checkout_start_date", "NOW()", $morder->user_id, $morder->membership_level);
//custom level to change user to
$custom_level = array(
'user_id' => $morder->user_id,
'membership_id' => $morder->membership_level->id,
'code_id' => $discount_code_id,
'initial_payment' => $morder->membership_level->initial_payment,
'billing_amount' => $morder->membership_level->billing_amount,
'cycle_number' => $morder->membership_level->cycle_number,
'cycle_period' => $morder->membership_level->cycle_period,
'billing_limit' => $morder->membership_level->billing_limit,
'trial_amount' => $morder->membership_level->trial_amount,
'trial_limit' => $morder->membership_level->trial_limit,
'startdate' => $startdate,
'enddate' => $enddate);
global $pmpro_error;
if(!empty($pmpro_error))
{
echo $pmpro_error;
ipnlog($pmpro_error);
}
if(pmpro_changeMembershipLevel($custom_level, $morder->user_id) !== false)
{
//update order status and transaction ids
$morder->status = "success";
$morder->payment_transaction_id = $txn_id;
if(!empty($_POST['subscr_id']))
$morder->subscription_transaction_id = $_POST['subscr_id'];
else
$morder->subscription_transaction_id = "";
$morder->saveOrder();
//add discount code use
if(!empty($discount_code) && !empty($use_discount_code))
{
$wpdb->query("INSERT INTO $wpdb->pmpro_discount_codes_uses (code_id, user_id, order_id, timestamp) VALUES('" . $discount_code_id . "', '" . $current_user->ID . "', '" . $morder->id . "', now())");
}
//save first and last name fields
if(!empty($_POST['first_name']))
{
$old_firstname = get_user_meta($morder->user_id, "first_name", true);
if(!empty($old_firstname))
update_user_meta($morder->user_id, "first_name", $_POST['first_name']);
}
if(!empty($_POST['last_name']))
{
$old_lastname = get_user_meta($morder->user_id, "last_name", true);
if(!empty($old_lastname))
update_user_meta($morder->user_id, "last_name", $_POST['last_name']);
}
//hook
do_action("pmpro_after_checkout", $morder->user_id);
//setup some values for the emails
if(!empty($morder))
$invoice = new MemberOrder($morder->id);
else
$invoice = NULL;
$user = get_userdata($morder->user_id);
$user->membership_level = $morder->membership_level; //make sure they have the right level info
//send email to member
$pmproemail = new PMProEmail();
$pmproemail->sendCheckoutEmail($user, $invoice);
//send email to admin
$pmproemail = new PMProEmail();
$pmproemail->sendCheckoutAdminEmail($user, $invoice);
return true;
}
//.........这里部分代码省略.........