Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ipokkel/2bcfca4e263c43f958dc7629eb357ef9 to your computer and use it in GitHub Desktop.
Save ipokkel/2bcfca4e263c43f958dc7629eb357ef9 to your computer and use it in GitHub Desktop.
Paid Memberships Pro Customization add billing and shipping fields to Add Member from Admin
<?php
/**
* Add Billing Address fields to the User Profile Edit page(s) and Add Member 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 show_pmpro_billing_address_fields_on_add_member() {
global $pmpro_countries;
// Don't break if PMPro is out of date or not loaded.
if ( ! function_exists( 'pmpro_add_user_field' ) ) { // pmprorh_add_registration_field
return;
}
//define the fields
$fields = array();
$fields[] = new PMPro_Field(
'pmpro_baddress1',
'text',
array(
'label' => 'Billing Address 1',
'profile' => 'only',
'addmember' => true,
)
);
$fields[] = new PMPro_Field(
'pmpro_baddress2',
'text',
array(
'label' => 'Billing Address 2',
'profile' => 'only',
'addmember' => true,
)
);
$fields[] = new PMPro_Field(
'pmpro_bcity',
'text',
array(
'label' => 'Billing City',
'profile' => 'only',
'addmember' => true,
)
);
$fields[] = new PMPro_Field(
'pmpro_bstate',
'text',
array(
'label' => 'Billing State',
'profile' => 'only',
'addmember' => true,
)
);
$fields[] = new PMPro_Field(
'pmpro_bzipcode',
'text',
array(
'label' => 'Billing Postal Code',
'size' => 10,
'profile' => 'only',
'addmember' => true,
)
);
$fields[] = new PMPro_Field(
'pmpro_bcountry',
'select',
array(
'label' => 'Billing Country',
'profile' => 'only',
'addmember' => true,
'options' => $pmpro_countries,
)
);
$fields[] = new PMPro_Field(
'pmpro_bphone',
'text',
array(
'label' => 'Billing Phone',
'profile' => 'only',
'addmember' => true,
)
);
// Add a field group to put our fields into.
pmpro_add_field_group( 'Billing Address' );
foreach ( $fields as $field ) {
pmpro_add_user_field( 'Billing Address', $field );
}
}
add_action( 'init', 'show_pmpro_billing_address_fields_on_add_member', 10 );
/**
* Add Shipping/Mailing Address fields to the Add Member 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/
*/
// Show Shipping Address fields on Add Member
function show_pmpro_shipping_address_fields_on_add_member() {
global $pagenow, $pmpro_countries;
// Don't break if PMPro is out of date or not loaded.
if ( ! function_exists( 'pmpro_add_user_field' ) ) { // pmprorh_add_registration_field
return;
}
// Don't load shipping details on User Profile page as it's already
// loaded by the pmpro-shipping plugin
if ( $pagenow !== 'admin.php' && ( empty( $_REQUEST['page'] ) || $_REQUEST['page'] !== 'pmpro-addmember' ) ) {
return;
}
//define the fields
$fields = array();
$fields[] = new PMPro_Field(
'pmpro_saddress1',
'text',
array(
'label' => 'Shipping Address 1',
'profile' => 'only_admin',
'addmember' => true,
)
);
$fields[] = new PMPro_Field(
'pmpro_saddress2',
'text',
array(
'label' => 'Shipping Address 2',
'profile' => 'only_admin',
'addmember' => true,
)
);
$fields[] = new PMPro_Field(
'pmpro_scity',
'text',
array(
'label' => 'Shipping City',
'profile' => 'only_admin',
'addmember' => true,
)
);
$fields[] = new PMPro_Field(
'pmpro_sstate',
'text',
array(
'label' => 'Shipping State',
'profile' => 'only_admin',
'addmember' => true,
)
);
$fields[] = new PMPro_Field(
'pmpro_szipcode',
'text',
array(
'label' => 'Shipping Postal Code',
'size' => 10,
'profile' => 'only_admin',
'addmember' => true,
)
);
$fields[] = new PMPro_Field(
'pmpro_scountry',
'select',
array(
'label' => 'Shipping Country',
'profile' => 'only_admin',
'addmember' => true,
'options' => $pmpro_countries,
)
);
$fields[] = new PMPro_Field(
'pmpro_sphone',
'text',
array(
'label' => 'Shipping Phone',
'profile' => 'only_admin',
'addmember' => true,
)
);
//add the fields into a new checkout_boxes are of the checkout page
foreach ( $fields as $field ) {
pmpro_add_user_field( 'profile', $field );
}
}
add_action( 'init', 'show_pmpro_shipping_address_fields_on_add_member', 20 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment