Forked from ideadude/show_pmpro_address_fields_on_edit_profile.php
Last active
April 13, 2021 18:41
-
-
Save pbrocks/4586a6629803d0d3a1814822d9261b7b to your computer and use it in GitHub Desktop.
Use PMPro Register Helper to add PMPro Billing Address fields to the edit user page for admins.
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 | |
/** | |
* Use PMPro Register Helper to add PMPro Billing Address fields to the edit user page for admins. | |
*/ | |
/** | |
* show_pmpro_address_fields_on_edit_profile Grabs the values from the billing fields which get filled in during checkout and displays on User Profile. | |
* | |
* @return array Array of Register Helper field objects | |
*/ | |
function show_pmpro_address_fields_on_edit_profile() { | |
// Require PMPro and PMPro Register Helper | |
if ( ! defined( 'PMPRO_VERSION' ) || ! defined( 'PMPRORH_VERSION' ) ) { | |
return; | |
} | |
// List the fields you want to include | |
$address_fields = array( | |
'pmpro_bfirstname' => 'First Name', | |
'pmpro_blastname' => 'Last Name', | |
'pmpro_baddress1' => 'Address 1', | |
'pmpro_baddress2' => 'Address 2', | |
'pmpro_bcity' => 'City', | |
'pmpro_bstate' => 'State', | |
'pmpro_bzipcode' => 'Zipcode', | |
'pmpro_bphone' => 'Phone', | |
); | |
// Define the fields | |
$fields = array(); | |
foreach ( $address_fields as $name => $label ) { | |
$fields[] = new PMProRH_Field( | |
$name, | |
'text', | |
array( | |
'label' => $label, | |
'size' => 40, | |
'profile' => 'only_admin', | |
'addmember' => true, | |
) | |
); | |
} | |
// Add new checkout box with label | |
pmprorh_add_checkout_box( 'billing_mailing_address', 'Billing/Mailing Address' ); | |
// Add fields into a new checkout_boxes area of checkout page | |
foreach ( $fields as $field ) { | |
pmprorh_add_registration_field( | |
'billing_mailing_address', // location on checkout page | |
$field // PMProRH_Field object | |
); | |
} | |
} | |
add_action( 'init', 'show_pmpro_address_fields_on_edit_profile' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This recipe is included in the blog post on "Display the Member’s Billing Address Fields on the Edit User Page for Admin Only" at Paid Memberships Pro here: https://www.paidmembershipspro.com/display-the-members-billing-address-fields-on-the-edit-user-page-for-admin-only/