Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ipokkel/2bc4f74ec8b9395cf467cd7224ff7896 to your computer and use it in GitHub Desktop.
Save ipokkel/2bc4f74ec8b9395cf467cd7224ff7896 to your computer and use it in GitHub Desktop.
Show and edit the Shipping Address fields on the Member Edit page for PMPro 3.0 and newer.
<?php
/**
* Show PMPro shipping address fields on the member 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 show_pmpro_shipping_address_fields_on_member_edit() {
global $pagenow, $pmpro_countries;
// Don't break if PMPro is out of date or not loaded.
if ( ! function_exists( 'pmpro_add_user_field' ) || ! class_exists( 'PMPro_Member_Edit_Panel_User_Fields' ) ) {
return;
}
// Let's only do this if the PMPro Shipping Address plugin is active.
if ( ! function_exists( 'pmproship_pmpro_checkout_boxes' ) ) {
return;
}
// Don't load shipping details on User Profile page as it's already
// loaded by the pmpro-shipping plugin
if ( 'admin.php' !== $pagenow && ( empty( $_REQUEST['page'] ) || 'pmpro-member' !== $_REQUEST['page'] ) ) {
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,
)
);
pmpro_add_field_group( 'Shipping Address' );
//add the fields into a new checkout_boxes are of the checkout page
foreach ( $fields as $field ) {
pmpro_add_user_field( 'Shipping Address', $field );
}
}
add_action( 'init', 'show_pmpro_shipping_address_fields_on_member_edit', 20 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment