Forked from strangerstudios/pmpro-address-for-free-levels.php
Created
July 11, 2014 01:17
-
-
Save messica/226c1cd00d91529299e0 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 | |
/* | |
Plugin Name: PMPro Address For Free Levels | |
Plugin URI: http://www.paidmembershipspro.com/wp/pmpro-address-for-free-levels/ | |
Description: Show address fields for free levels also with Paid Memberships Pro | |
Version: .1 | |
Author: Stranger Studios | |
Author URI: http://www.strangerstudios.com | |
*/ | |
/* | |
Show address fields for free levels too. | |
Add this code to your active theme's functions.php or a custom plugin. | |
*/ | |
//keep address fields shown on checkout page | |
function my_pmpro_checkout_boxes_require_address() | |
{ | |
?> | |
<script> | |
var pmpro_show_billing_address_fields_timer; | |
function showBillingAddressFields() | |
{ | |
jQuery('#pmpro_billing_address_fields').show(); | |
pmpro_show_billing_address_fields_timer = setTimeout(function(){showBillingAddressFields();}, 200); | |
} | |
jQuery(document).ready(function() { | |
//show it and keep showing it | |
showBillingAddressFields(); | |
<?php | |
//remove billing from address title if the level is free | |
global $pmpro_level; | |
if(pmpro_isLevelFree($pmpro_level)) | |
{ | |
?> | |
//change heading | |
jQuery('#pmpro_billing_address_fields th').html('Address'); | |
<?php | |
} | |
?> | |
}); | |
</script> | |
<?php | |
} | |
add_action("pmpro_checkout_boxes", "my_pmpro_checkout_boxes_require_address"); | |
//make sure address fields are required | |
function my_pmpro_required_user_fields($fields) | |
{ | |
global $bfirstname, $blastname, $baddress1, $bcity, $bstate, $bzipcode, $bcountry, $bphone, $bemail; | |
$fields["bfirstname"] = $bfirstname; | |
$fields["blastname"] = $blastname; | |
$fields["baddress1"] = $baddress1; | |
$fields["bcity"] = $bcity; | |
$fields["bstate"] = $bstate; | |
$fields["bzipcode"] = $bzipcode; | |
$fields["bphone"] = $bphone; | |
$fields["bemail"] = $bemail; | |
$fields["bcountry"] = $bcountry; | |
return $fields; | |
} | |
add_action("pmpro_required_user_fields", "my_pmpro_required_user_fields"); | |
/* | |
* Save billing fields when using PayPal | |
*/ | |
function my_pmpro_paypalexpress_session_vars() { | |
$_SESSION['bfirstname'] = $_REQUEST['bfirstname']; | |
$_SESSION['blastname'] = $_REQUEST['blastname']; | |
$_SESSION['baddress1'] = $_REQUEST['baddress1']; | |
$_SESSION['baddress2'] = $_REQUEST['baddress2']; | |
$_SESSION['bcity'] = $_REQUEST['bcity']; | |
$_SESSION['bstate'] = $_REQUEST['bstate']; | |
$_SESSION['bzipcode'] = $_REQUEST['bzipcode']; | |
$_SESSION['bphone'] = $_REQUEST['bphone']; | |
$_SESSION['bemail'] = $_REQUEST['bemail']; | |
$_SESSION['bcountry'] = $_REQUEST['bcountry']; | |
} | |
add_action('pmpro_paypalexpress_session_vars', 'my_pmpro_paypalexpress_session_vars'); | |
//load vars back into $_REQUEST | |
function my_init() { | |
if(!empty($_REQUEST['review']) && !empty($_REQUEST['token'])) { | |
$_REQUEST['bfirstname'] = $_SESSION['bfirstname']; | |
$_REQUEST['blastname'] = $_SESSION['blastname']; | |
$_REQUEST['baddress1'] = $_SESSION['baddress1']; | |
$_REQUEST['baddress2'] = $_SESSION['baddress2']; | |
$_REQUEST['bcity'] = $_SESSION['bcity']; | |
$_REQUEST['bstate'] = $_SESSION['bstate']; | |
$_REQUEST['bzipcode'] = $_SESSION['bzipcode']; | |
$_REQUEST['bphone'] = $_SESSION['bphone']; | |
$_REQUEST['bemail'] = $_SESSION['bemail']; | |
$_REQUEST['bcountry'] = $_SESSION['bcountry']; | |
} | |
} | |
add_action('init', 'my_init'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment