public

Show address fields for free levels also with Paid Memberships Pro.

  • Download Gist
pmpro-address-for-free-levels.php
PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
<?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");

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.