Forked from pbrocks/pmpro-billing-fields-to-profile.php
Last active
November 9, 2022 10:37
-
-
Save JarrydLong/7ef623b84926307d38ca080c04d3fc78 to your computer and use it in GitHub Desktop.
Add the billing fields created by Paid Memberships Pro to your user Profile for easy editing and inclusion in the Members List CSV.
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 | |
/** | |
* This recipe will only add the billing fields to the user profile edit page. | |
* | |
* You can add this recipe to your site by creating a custom plugin | |
* or using the Code Snippets plugin available for free in the WordPress repository. | |
* Read this companion article for step-by-step directions on either method. | |
* https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/ | |
*/ | |
function mypmpro_profile_billing_fields() { | |
global $pmpro_countries; | |
// check for register helper | |
if ( ! function_exists( 'pmprorh_add_registration_field' ) ) { | |
return; | |
} | |
// define the fields | |
$fields = array(); | |
$fields[] = new PMProRH_Field( | |
'pmpro_baddress1', | |
'text', | |
array( | |
'label' => 'Billing Address 1', | |
'size' => 40, | |
'profile' => 'only', | |
'required' => false, | |
) | |
); | |
$fields[] = new PMProRH_Field( | |
'pmpro_baddress2', | |
'text', | |
array( | |
'label' => 'Billing Address 2', | |
'size' => 40, | |
'profile' => 'only', | |
'required' => false, | |
) | |
); | |
$fields[] = new PMProRH_Field( | |
'pmpro_bcity', | |
'text', | |
array( | |
'label' => 'Billing City', | |
'size' => 40, | |
'profile' => 'only', | |
'required' => false, | |
) | |
); | |
$fields[] = new PMProRH_Field( | |
'pmpro_bstate', | |
'text', | |
array( | |
'label' => 'Billing State', | |
'size' => 10, | |
'profile' => 'only', | |
'required' => false, | |
) | |
); | |
$fields[] = new PMProRH_Field( | |
'pmpro_bzipcode', | |
'text', | |
array( | |
'label' => 'Billing Postal Code', | |
'size' => 10, | |
'profile' => 'only', | |
'required' => false, | |
) | |
); | |
$fields[] = new PMProRH_Field( | |
'pmpro_bcountry', | |
'select', | |
array( | |
'label' => 'Billing Country', | |
'profile' => 'only', | |
'required' => false, | |
'options' => array_merge( array( '' => '- choose one -' ), $pmpro_countries ), | |
) | |
); | |
$fields[] = new PMProRH_Field( | |
'pmpro_bphone', | |
'text', | |
array( | |
'label' => 'Billing Phone', | |
'size' => 40, | |
'profile' => 'only', | |
'required' => false, | |
) | |
); | |
// add the fields into a new checkout_boxes are of the checkout page | |
foreach ( $fields as $field ) { | |
pmprorh_add_registration_field( 'profile', $field ); | |
} | |
} | |
add_action( 'init', 'mypmpro_profile_billing_fields' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Updated the recipe to reflect this. Thanks for catching that @dparker1005