Created
January 20, 2016 16:28
-
-
Save raujohn/1ec43cd3bd01beb00d9d to your computer and use it in GitHub Desktop.
This file contains 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 | |
/* | |
Plugin Name: PMPro Check Levels | |
Plugin URI: http://www.paidmembershipspro.com/wp/pmpro-check-levels/ | |
Description: A collection of customizations useful when allowing users to pay by check for Paid Memberships Pro levels. | |
Version: .2 | |
Author: Stranger Studios | |
Author URI: http://www.strangerstudios.com | |
*/ | |
/* | |
Change gateway to "check" for the levels specified | |
*/ | |
function pmprocl_init_check_gateway_for_levels() | |
{ | |
if(!empty($_REQUEST['pay_by_check'])) | |
{ | |
//set a usermeta stating this person will be paying by check | |
$user_id = get_current_user_id(); | |
update_user_meta($user_id, 'payment_type', 'check'); | |
//set gateway to check and make check a valid gateway | |
$_REQUEST['gateway'] = "check"; | |
add_filter('pmpro_valid_gateways', create_function('$gateways', '$gateways[]="check"; return $gateways;')); | |
//set this global so we don't require billing fields | |
global $pmpro_requirebilling; | |
$pmpro_requirebilling = false; | |
//don't use the pmpro-add-paypal-express on this level | |
remove_action("pmpro_checkout_boxes", "pmproappe_pmpro_checkout_boxes", 5); | |
remove_filter("pmpro_valid_gateways", "pmproappe_pmpro_valid_gateways"); | |
} else { | |
//set a usermeta stating this person will be paying by credit | |
$user_id = get_current_user_id(); | |
update_user_meta($user_id, 'payment_type', 'credit'); | |
} | |
} | |
add_action('init', 'pmprocl_init_check_gateway_for_levels', 0); | |
/* | |
Fix admin change email when changing members who paid by check. | |
We don't want to mention "free" /etc. | |
*/ | |
function pmprocl_pmpro_email_data($email_data, $email) | |
{ | |
// Get user info | |
if(isset($email_data['user_login'])) | |
{ | |
$user = get_user_by( 'login', $email_data['user_login'] ); | |
$membership_level = pmpro_getMembershipLevelForUser($user->ID); | |
} | |
// Get last order details | |
$order = new MemberOrder(); | |
$order->getLastMemberOrder($user->ID, "cancelled"); | |
// Check to make sure there changing levels and are not cancelling | |
if(isset($email_data["membership_change"]) && $order->gateway == 'check' && !empty($membership_level->ID)) | |
$email_data["membership_change"] = str_replace(". This membership is free", "", $email_data["membership_change"]); | |
return $email_data; | |
} | |
add_filter('pmpro_email_data', 'pmprocl_pmpro_email_data', 10, 2); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment